1
我在Jquery Mobile中有一个名为findclosestLink的函数,它检查用户在屏幕上单击时点击的内容。jquery - 函数返回“null” - 如何检查这个?
是这样的:
var link = find(findClosestLink(event.target);
findClosestLink: function (ele) {
var self = this;
while (ele){
if (ele.nodeName.toLowerCase() == "a"){
break;
}
ele = ele.parentNode;
}
console.log(ele);
return ele;
}
如果我在屏幕上点击某处ELE控制台为 “空” 和我的变量变成 “[]”。
问题:我该如何检查这个空的东西“[]”?
所有这些不工作:
if (link == 'null') { console.log("null"); }
if (link == '') { console.log("empty");}
if (link == 'undefined') { console.log("undefined"); }
if (link == []) { console.log("empty object"); }
if (link == $()) { console.log("empty dings"); }
感谢您的帮助!
在前面的typeof尝试。例子`if(typeof link =='null')...' – 2011-12-15 12:52:28
`link == null`怎么样? – 2011-12-15 12:58:01
@Tricker - 不起作用 – frequent 2011-12-15 13:01:08