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

查看所有标签

Algorithms for Image Processing and Computer Vision

Algorithms for Image Processing and Computer Vision

Parker, J. R. / 2010-12 / 687.00元

A cookbook of algorithms for common image processing applications Thanks to advances in computer hardware and software, algorithms have been developed that support sophisticated image processing with......一起来看看 《Algorithms for Image Processing and Computer Vision》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器