jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
css(properties) |
css(properties)
把一个“名/值对”对象设置为所有匹配元素的样式属性。 这是一种在所有匹配的元素上设置大量样式属性的最佳方式。 返回值:jQuery 参数:
为所有p元素设置color和background样式属性。 $("p").css({ color: "red", background: "blue" }); HTML 代码: <p>Test Paragraph.</p> 结果: <p style="color:red; background:blue;">Test Paragraph.</p> css( properties ) Set a key/value object as style properties to all matched elements. This serves as the best way to set a large number of style properties on all matched elements. Return value: jQuery
Example: Sets color and background styles to all p elements. $("p").css({ color: "red", background: "blue" }); Before: <p>Test Paragraph.</p>Result: <p style="color:red; background:blue |