jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
attr(properties) |
attr(properties)
将一个“名/值”形式的对象设置为所有匹配元素的属性。 这是一种在所有匹配元素中批量设置很多属性的最佳方式。 返回值:jQuery 参数:
示例: 为所有图像设置src和alt属性。 $("img").attr({ src: "test.jpg", alt: "Test Image" }); HTML 代码: <img/> 结果: <img src="test.jpg" alt="Test Image"/> attr( properties ) 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. Return value: jQuery
Example: Sets src and alt attributes to all images. $("img").attr({ src: "test.jpg", alt: "Test Image" });Before: <img/>Result: <img src="test.jpg" alt="Test Image"/> |