jQuery API | 返回首页目录 | jQuery API 中英文对照版 |
attr |
attr(name)
取得第一个匹配元素的属性值。通过这个方法可以方便地从第一个匹配元素中获取一个属性的值。 返回值:Object 参数:
返回文档中第一个图像的src属性值。 $("img").attr("src"); HTML 代码: <img src="test.jpg"/> 结果: test.jpg attr( name ) Access a property on the first matched element. This method makes it easy to retrieve a property value from the first matched element. If the element does not have an attribute with such a name, undefined is returned. Return value: Object
Example: Returns the src attribute from the first image in the document. $("img").attr("src");Before: <img src="test.jpg"/>Result: test.jpg |