属性的格式如下:

$.fn.attr

该格式既可以获取属性的值也可以设置属性的值。示例如下:

设置属性

1 // Setting attributes
2 $("a").attr( "href", "allMyHrefsAreTheSameNow.html" );
3 $("a").attr({
4 title: "all titles are the same too!",
5 href: "somethingNew.html"
6 });

获取属性

1 // Getting attributes
2 $("a").attr("href"); // returns the href for the first a element in the document

 

posted on 2013-04-13 14:17  一天不进步,就是退步  阅读(181)  评论(0编辑  收藏  举报