参数
name (String) : 属性名称
示例
返回文档中第一个图像的src属性值。
HTML 代码:
jQuery 代码:
$("img").attr("src");
结果:
https://www.gxlcms.com/test.jpg
---------------------------------------------------------------------------------------------------------------------------------------
attr(properties)
将一个“名/值”形式的对象设置为所有匹配元素的属性。
这是一种在所有匹配元素中批量设置很多属性的最佳方式。 注意,如果你要设置对象的class属性,你必须使用'className' 作为属性名。或者你可以直接使用.addClass( class ) 和 .removeClass( class ).
Set a key/value object as properties to all matched elements.
This serves as the best way to set a large number of properties on all matched elements. Note that you must use 'className' as key if you want to set the class-Attribute. Or use .addClass( class ) or .removeClass( class ).
返回值
jQuery
参数
properties (Map) : 作为属性的“名/值对”对象
示例
为所有图像设置src和alt属性。
HTML 代码:
jQuery 代码:
$("img").attr("title", function() { return this.src });
结果:
---------------------------------------------------------------------------------------------------------------------------------------
removeAttr(name)
从每一个匹配的元素中删除一个属性
Remove an attribute from each of the matched elements.
返回值
jQuery
参数
name (String) : 要删除的属性名
示例
将文档中图像的src属性删除
HTML 代码:
jQuery 代码:
$("img").removeAttr("src");
结果:
[ ]
Copyright © 2019- shuicheng.net 版权所有
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务