Possible Duplicate: (可能重复:) Check existence of an attribute with JQuery (使用JQuery检查属性是否存在)
Possible Duplicate:
(可能重复:) Check existence of an attribute with JQuery
(使用JQuery检查属性是否存在)
How do you check if there is an attribute on an element in jQuery?
(你如何检查jQuery中的元素是否有属性?)
hasClass
attr
(与hasClass类似,但是attr ?)
For example,
(例如,)
if ($(this).hasAttr("name")) { // ... }
var attr = $(this).attr('name'); // For some browsers, `attr` is undefined; for others, // `attr` is false. Check for both. if (typeof attr !== typeof undefined && attr !== false) { // ... }
2.1m questions
2.1m answers
60 comments
56.9k users