8.7w+
社区成员
var res=$("label").filter(function(){
if((this.hasAttribute && !this.hasAttribute("for")) || (!this.getAttributeNode("for").specified))
return true;
}).html();
alert(res)
$(function() {
alert($('label').not($('label[for]')).html())
});
alert(undefined==null)//判断值
alert(undefined===null)//===判断引用
var res=$("label").filter(function(){
if(this.hasAttribute && !this.hasAttribute("for") || this.getAttribute("for")===null)
//MSDN:If the attribute is not present, this method returns null.
//MDC:If the named attribute does not exist, the value returned will either be null or "" (the empty string);
//如果不考虑IE6可以直接使用hasAttribute判断
return true;
}).html();
alert(res)
var res=$("label").filter(function(){
if(this.getAttribute("for")===null)//If the attribute is not present, this method returns null.
return true;
}).html();
alert(res)