可能重複:
Is there an 「exists」 function for jQuery
jQuery determining if element exists on page檢查元素存在
if(tr)
時TR不是一個元素返回true,我如何檢查它是否存在一個元素?
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
它評估爲true的原因是因爲您得到一個jQuery對象,無論它是否找到元素,它總是被視爲真實的。 – BoltClock 2011-01-25 16:16:13