JQuery官方学习资料,译:Attributes

  • Attributes

元素的属性可以为你的应用程序包含有用的信息,重要的是能够获取和设置它。

  • .attr()方法

.attr()方法是可获取和可设置的,在设置状态下,.attr()可以接收一个key和一个value,或者一个对象包含了一个或多个键值对。

    • setter

$( "a" ).attr( "href", "allMyHrefsAreTheSameNow.html" );

$( "a" ).attr({

title: "all titles are the same too!",

href: "somethingNew.html"

});

    • getter
$( "a" ).attr( "href" ); // 返回文档中的第一个元素的href