我已经知道如何检查文档准备就绪时存在的元素:
jQuery.fn.exists = function () {
return jQuery(this).length > 0;
}
但是这个方法不知道使用 AJAX 添加的元素。有人知道该怎么做吗?
我已经知道如何检查文档准备就绪时存在的元素:
jQuery.fn.exists = function () {
return jQuery(this).length > 0;
}
但是这个方法不知道使用 AJAX 添加的元素。有人知道该怎么做吗?
一旦加载了 ajax 并将其附加到 DOM,该方法就会执行。你可以重写一下:
jQuery.existsin = function (what, where) {
return jQuery(where).find(what).length > 0;
}
你可以在ajax成功:
function(data, status){
if(jQuery.existsin('selector', data)){
//do foo
}
}
也许这有帮助: http: //plugins.jquery.com/project/livequery/