Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

jQuery - css() 方法


jQuery css() 方法

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


返回 CSS 属性

要返回指定 CSS 属性的值,请使用以下语法

css("propertyname");

以下示例将返回第一个匹配元素的 background-color 值

示例

$("p").css("background-color");
亲自尝试 »

设置 CSS 属性

要设置指定的 CSS 属性,请使用以下语法

css("propertyname","value");

以下示例将为所有匹配元素设置 background-color 值

示例

$("p").css("background-color", "yellow");
亲自尝试 »


设置多个 CSS 属性

要设置多个 CSS 属性,请使用以下语法

css({"propertyname":"value","propertyname":"value",...});

以下示例将为所有匹配元素设置 background-color 和 font-size

示例

$("p").css({"background-color": "yellow", "font-size": "200%"});
亲自尝试 »

jQuery 练习

通过练习测试自己

练习

使用 css() 方法为 <p> 元素添加粉红色背景颜色。

$("p").("", "");

开始练习


jQuery CSS 参考

有关所有 jQuery CSS 方法的完整概述,请访问我们的 jQuery HTML/CSS 参考


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.