jQuery css() 方法

jQuery 教程 · 2019-03-27 12:43:00

实例

设置所有 <p> 元素的 color 属性:

$("button").click(function(){ $("p").css("color","red"); });

定义和用法

css() 方法为被选元素设置或返回一个或多个样式属性。

当用于返回属性:
该方法返回第一个匹配元素的指定 CSS 属性值。
然而,简写的 CSS 属性(比如 "background" 和 "border")不被完全支持,且当用于返回属性值时,在不同的浏览器中有不同的结果。

当用于设置属性:
该方法为所有匹配元素设置指定 CSS 属性。

语法

返回 CSS 属性值:

  
    $(selector).css(property)

设置 CSS 属性和值:

  
    $(selector).css(property,value)

使用函数设置 CSS 属性和值:

  
    $(selector).css(property,function(index,currentvalue))
  

设置多个属性和值:

  
    $(selector).css({属性:value, 属性:value, 
...})
  

参数 描述
property 规定 CSS 属性名称,比如 "color"、"font-weight" 等等。
value 规定 CSS 属性的值,比如 "red"、"bold" 等等。
function(index,currentvalue) 规定返回 CSS 属性新值的函数。
  • index - 返回集合中元素的 index 位置。
  • currentvalue - 返回 CSS 属性的当前值。

点击查看所有 jQuery 教程 文章: https://codercto.com/courses/l/35.html

查看所有标签

The Seasoned Schemer

The Seasoned Schemer

Daniel P. Friedman、Matthias Felleisen / The MIT Press / 1995-12-21 / USD 38.00

drawings by Duane Bibbyforeword and afterword by Guy L. Steele Jr.The notion that "thinking about computing is one of the most exciting things the human mind can do" sets both The Little Schemer (form......一起来看看 《The Seasoned Schemer》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试