jquery基础教程四[css的操作之css,height和width]

首先我们看看 css(key, value) 和 css(name)
css(key, value)

在所有匹配的元素中,设置一个样式属性的值。

css(name)

访问第一个匹配元素的样式属性。使用这个方法可以很容易地取得第一个匹配元素的样式属性的值。

css(properties)

把一个“名/值对”对象设置为所有匹配元素的样式属性。 这是一种在所有匹配的元素上设置大量样式属性的最佳方式。

首先我们看看

css(key, value)

我们看看下面代码

$("#css1").click(function(){
       $
(this).css("border","2px dashed #000000");
    
})
当鼠标单击
IDcss1的元素 此元素的border属性设置成 "2px dashed #000000"

css(name)

$("#css2").click(function(){
       $
(this).css("border","2px dashed #6600FF");
      
alert($(this).css("border"));
    
})
 
$
(this).css("border","2px dashed #6600FF");
 
当鼠标单击
IDcss2的元素 此元素的border属性设置成 "2px dashed #6600FF"
 
alert($(this).css("border"));
 
获得
border的属性值.

css(properties)

$("#css3").click(function(){
       $
(this).css({ color: "white", background: "red" });
    
})
 
当鼠标单击
IDcss3的元素 样式colorwihte backgroundred

下面我们看看height和width用法 其实从单词意思上也应该知道的差不多

height(val)

为每个匹配的元素设置CSS高度(height)属性的值。如果没有明确指定单位(如:em或%),使用px。

height()

取得第一个匹配元素当前计算的高度值(px)。

height(val)

$("#height1").click(function(){
       $
(this).height("200px");
    
alert($(this).height());
    
})
$
(this).height("200px"); 当鼠标单击IDheight1的元素 此元素的高度将变成200px
 
alert($(this).height());显示height的值

width(val) width() 和height是一样的 只不过就是设置宽度.这里就不多说了.

GOTOP3 条评论 To jquery基础教程四[css的操作之css,height和width]

  1. xiaorsz 说道:

    不错,写的很详细!!

  2. Lubbykko 说道:

    Good site! Interesting information.. )

  3. 最新电影 说道:

    谢谢,学习了

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

无觅相关文章插件,快速提升流量