1. Setting individual properties
//第一个参数:需要设置的属性名//第二个参数:对应的属性值attr(name, value);//用法举例$("img").attr("title","哎哟,不错哦");$("img").attr("alt","哎哟,不错哦");
2. Setting multiple properties
//参数是一个对象,包含了需要设置的属性名和属性值attr(obj)//用法举例$("img").attr({ title:"哎哟,不错哦", alt:"哎哟,不错哦", style:"opacity:.5"});
3. Get Properties
//to get the property name, return the corresponding property value attr (name) //usage Example var otitle = $ ( "img"). attr ( "title" ); alert (otitle);
note:
- When you get a property, you get only the property that corresponds to the first element, just like the CSS method
-
"Case: Beauty Album"
4. Removing attributes
//参数:需要移除的属性名,如果传空,那么不会有任何操作,注意,并不是移除所有的属性。区分removeClass。removeAttr(name);//用法举例$("img").removeAttr("title");
Prop Method
note:
//设置属性$(":checked”).prop("checked",true);//获取属性$(":checked").prop("checked");//返回true或者false
jquery Action Properties