jQuery Css方法
生活随笔
收集整理的這篇文章主要介紹了
jQuery Css方法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
jQuery css() 方法
css() 方法設(shè)置或返回被選元素的一個(gè)或多個(gè)樣式屬性。
返回 CSS 屬性
如需返回指定的 CSS 屬性的值,請(qǐng)使用如下語(yǔ)法:
css("propertyname");下面的例子將返回首個(gè)匹配元素的 background-color 值:
<script> $(document).ready(function(){$("button").click(function(){alert("背景顏色 = " + $("p").css("background-color"));}); }); </script> </head><body> <h2>這是一個(gè)標(biāo)題</h2> <p style="background-color:#ff0000">這是一個(gè)段落。</p> <p style="background-color:#00ff00">這是一個(gè)段落。</p> <p style="background-color:#0000ff">這是一個(gè)段落。</p> <button>返回第一個(gè) p 元素的 background-color </button>設(shè)置 CSS 屬性
如需設(shè)置指定的 CSS 屬性,請(qǐng)使用如下語(yǔ)法:
css("propertyname","value");下面的例子將為所有匹配元素設(shè)置 background-color 值:
$("p").css("background-color","yellow");設(shè)置多個(gè) CSS 屬性
如需設(shè)置多個(gè) CSS 屬性,請(qǐng)使用如下語(yǔ)法:
css({"propertyname":"value","propertyname":"value",...});下面的例子將為所有匹配元素設(shè)置 background-color 和 font-size:
$("p").css({"background-color":"yellow","font-size":"200%"});
轉(zhuǎn)載于:https://www.cnblogs.com/tanlei-sxs/p/9841668.html
總結(jié)
以上是生活随笔為你收集整理的jQuery Css方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: docker与kuberentes基本概
- 下一篇: 1024活动第三天