jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
css(key, value) |
css(key, value)
在所有匹配的元素中,设置一个样式属性的值。 返回值:jQuery 参数:
把所有段落的color样式属性值改为红色。 $("p").css("color","red"); HTML 代码: <p>Test Paragraph.</p> 结果: <p style="color:red;">Test Paragraph.</p> 示例:把所有段落的left样式属性值设置为"30px" $("p").css("left",30); HTML 代码: <p>Test Paragraph.</p> 结果: <p style="left:30px;">Test Paragraph.</p> Set a single style property to a value, on all matched elements. If a number is provided, it is automatically converted into a pixel value. Return value: jQuery
Example: Changes the color of all paragraphs to red $("p").css("color","red");Before: <p>Test Paragraph.</p> Result: <p style="color:red;">Test Paragraph.</p>
Example: Changes the left of all paragraphs to "30px" $("p").css("left",30);Before: <p>Test Paragraph.</p>Result: <p style="left:30px;">Test Paragraph.</p> |