jquery中 css;是什么意思

html-css025

jquery中 css;是什么意思,第1张

css(name|pro|[,val|fn])

概述

访问匹配元素的样式属性。

jQuery 1.8中,当你使用CSS属性在css()或animate()中,我们将根据浏览器自动加上前缀(在适当的时候),比如("user-select", "none")在Chrome/Safari浏览器中我们将设置为"-webkit-user-select", Firefox会使用"-moz-user-select", IE10将使用"-ms-user-select".

参数

nameStringV1.0

要访问的属性名称

nameArrayV1.9

一个或多个CSS属性组成的一个数组

propertiesMapV1.0

要设置为样式属性的名/值对

name,valueString, NumberV1.4

属性名,属性值

name,function(index, value)String,FunctionV1.0

1:属性名

2:此函数返回要设置的属性值。接受两个参数,index为元素在对象集合中的索引位置,value是原先的属性值。

参考文献:http://jquery.cuishifeng.cn/css.html

jquery中css()方法可以并列多个属性。如下参考

/*css(properties)

把一个“名/值对”对象设置为所有匹配元素的样式属性。

这是一种在所有匹配的元素上设置大量样式属性的最佳方式。

*/

例如:

$("p").css({ color: "#ff0011", background: "blue" })

$("p").css({ "margin-left": "10px", "background-color": "blue" })