ITeye博客

jquery-元素属性操作

小丑鱼0703 · 2015-03-03 17:33 · jquery · Web前端 · Markdown

**attr(attributeName) 或者attr(attributeName,value) ** 设置或返回第一个匹配元素的属性值


<style>
  em { color:blue; font-weight:bold; }
</style>
<p>a<em title="huge, gigantic">large</em> orange</p> 
 The title of the emphasis is:<div></div> 
<script>
var title = $("em").attr("title");
  $("div").text(title);//结果:The title of the emphasis is:huge, gigantic
</script>

  $("em").attr({'title':'big','value':'me'});  
  $("div").text($("em").attr("title"));//结果:The title of the emphasis is:big 

http://www.css88.com/jqapi-1.9/attr/

**removeAttr(attributeName) ** 为匹配的元素集合中的每个元素中移除一个属性

---对应原生removeAttribute() 函数

  $("em").removeAttr("title");
  alert($("em").attr("title"));//undefined

http://www.css88.com/jqapi-1.9/removeAttr/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。