检查元素是否存在 [英] Check if element exists
本文介绍了检查元素是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if(tr)当tr不是元素时,code>返回true,如何检查它是否是一个元素?
if(tr)
is returning true when tr is not an element, how do I check whether it's an element that exists?
var tr = $('#parts-table .no-data').parent();
$('.delete', row).bind('click', function (e) {
that.delete(e.currentTarget);
});
console.log(tr);
if (tr) //returns true when it shouldn't
推荐答案
检查其长度
属性:
if(tr.length) {
// exists
}
if(tr)
总是求值为true,因为jQuery对象或任何 JavaScript对象,总是很简单。
if(tr)
always evaluates to true because a jQuery object, or any JavaScript Object for that matter, is always truthy.
这篇关于检查元素是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文