您的位置:首页 > Web前端 > JQuery

jQuery 判断是否包含某个属性

2015-12-28 22:07 603 查看
1、Get the attribute, check the value

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) {
// Element has this attribute
}


2、Native JavaScript has a way

$(this)[0].hasAttribute("name");

jQObject[0].hasAttribute("name");


3、Filter the selection

$(this).is('[name]');

$(this).filter("[name='choice']");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: