jQuery缓存的对象的更新的有关问题
jQuery缓存的对象的更新的问题
例如
<p aaa="123">words</p>
<script>
var $cache1=$("p");
alert( $cache1.length ); //1
alert( $cache1.attr("aaa") ); //123
$("p").remove();
alert( $cache1.length ); //1
alert( $cache1.attr("aaa") ); //123
</script>
怎么检查缓存的jQuery对象包含的一个或者多个dom是否继续存在?
如果重新选择的话还要读取整个dom树,现在dom很复杂,选择器也很复杂,对效率要求很高
所以我想不必重新读整个dom,只是检查缓存的这几个dom是否继续存在
jquery有自带的函数来实现吗,或者有什么其它的办法吗?
谢谢了~~~~
------解决思路----------------------
$(document.body).find(dom)
用find检索判断是否有记录
------解决思路----------------------
通过对象的parent方法来判断。。被移除的对象没有parent对象
see this:http://*.com/questions/3086068/how-do-i-check-whether-a-jquery-element-is-in-the-dom
------解决思路----------------------
$cache1=$cache1.not($("p").remove());
例如
<p aaa="123">words</p>
<script>
var $cache1=$("p");
alert( $cache1.length ); //1
alert( $cache1.attr("aaa") ); //123
$("p").remove();
alert( $cache1.length ); //1
alert( $cache1.attr("aaa") ); //123
</script>
怎么检查缓存的jQuery对象包含的一个或者多个dom是否继续存在?
如果重新选择的话还要读取整个dom树,现在dom很复杂,选择器也很复杂,对效率要求很高
所以我想不必重新读整个dom,只是检查缓存的这几个dom是否继续存在
jquery有自带的函数来实现吗,或者有什么其它的办法吗?
谢谢了~~~~
------解决思路----------------------
$(document.body).find(dom)
用find检索判断是否有记录
------解决思路----------------------
通过对象的parent方法来判断。。被移除的对象没有parent对象
<p aaa="123">words1</p><p aaa="123">words2</p>
<script>
var $cache1 = $("p");
alert($cache1.length); //1
alert($cache1.attr("aaa")); //123
$("p:eq(0)").remove();
for (var i = 0; i < $cache1.size(); i++) {
if ($cache1.eq(i).parent().size() == 0) alert('元素“'+$cache1.eq(i).html()+'”不在DOM树中');
}
</script>
see this:http://*.com/questions/3086068/how-do-i-check-whether-a-jquery-element-is-in-the-dom
------解决思路----------------------
$cache1=$cache1.not($("p").remove());