1

我已经知道如何检查文档准备就绪时存在的元素:

jQuery.fn.exists = function () { 
  return jQuery(this).length > 0; 
}

但是这个方法不知道使用 AJAX 添加的元素。有人知道该怎么做吗?

4

2 回答 2

3

一旦加载了 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
  }
}
于 2009-12-04T13:11:11.980 回答
0

也许这有帮助: http: //plugins.jquery.com/project/livequery/

于 2009-12-04T13:31:57.727 回答