jQuery API/1.1.1/CSS
2007-01-23 21:48 无常 阅读(996) 评论(0) 编辑 收藏 举报css( name )
访问第一个匹配元素的style属性。此方法使得第一个匹配元素的style属性更加容易。
Return value: String
Parameters:
name (String)
: 要访问的CSS属性名。
Example:
检索第一段的颜色样式。
$("p").css("color");
Before:
<p style="color:red;">Test Paragraph.</p>
Result:
"red"
Example:
检索第一段的font-weight样式。
$("p").css("font-weight");
Before:
<p style="font-weight: bold;">Test Paragraph.</p>
Result:
"bold"
css( properties )
将key/value 样式属性设置到所有匹配元素。
这是个给所有匹配元素设置大量CSS的好方法。
Return value: jQuery
Parameters:
properties (Map)
: Key/value pairs to set as style properties.
Example:
设置所有段落元素设置color和background样式。
$("p").css({ color: "red", background: "blue" });
Before:
<p>Test Paragraph.</p>
Result:
<p style="color:red; background:blue;">Test Paragraph.</p>
css( key, value )
给所有匹配的元素设置单个样式。如果vale是一个数字,将自动转换为piexl格式。
Return value: jQuery
Parameters:
key (String)
: 属性名value (String|Number)
: 属性值。
Example:
将所有段落的color样式设置为红色。
$("p").css("color","red");
Before:
<p>Test Paragraph.</p>
Result:
<p style="color:red;">Test Paragraph.</p>
Example:
将所有段落的left样式改为30px。
$("p").css("left",30);
Before:
<p>Test Paragraph.</p>
Result:
<p style="left:30px;">Test Paragraph.</p>
height()
取得第一个匹配元素的像素高。
Return value: String
Example:
$("p").height();
Before:
<p>This is just a test.</p>
Result:
300
height( val )
给所有匹配的元素设置CSS宽度。如果没指定单位(如'em'或'%')则自动加了'px'单位。
Return value: jQuery
Parameters:
val (String|Number)
:设置CSS属性为指定值。
Example:
$("p").height(20);
Before:
<p>This is just a test.</p>
Result:
<p style="height:20px;">This is just a test.</p>
Example:
$("p").height("20em");
Before:
<p>This is just a test.</p>
Result:
<p style="height:20em;">This is just a test.</p>
width()
取得第一个匹配元素的像素宽度。
Return value: String
Example:
$("p").width();
Before:
<p>This is just a test.</p>
Result:
300
width( val )
设置每个匹配元素的CSS宽度。如果没指定单位(如'em'或'%')则自动加了'px'单位。
Return value: jQuery
Parameters:
val (String|Number)
: 设置CSS属性为指定值。
Example:
$("p").width(20);
Before:
<p>This is just a test.</p>
Result:
<p style="width:20px;">This is just a test.</p>
Example:
$("p").width("20em");
Before:
<p>This is just a test.</p>
Result:
<p style="width:20em;">This is just a test.</p>
无常翻译:http://wuchang.cnblogs.com
wuChang@guet.edu.cn
QQ: 3263262
Retrieved from "http://www.docs.jquery.com/API/1.1.1/CSS"