简体   繁体   English

如何清除jQuery DOM缓存?

[英]How can I clear the jQuery DOM cache?

How can I clear the jQuery DOM cache? 如何清除jQuery DOM缓存? I am still in the middle of developing and testing a jQuery Mobile application, and I keep seeing old versions of my code pop up and try to be executed. 我仍在开发和测试jQuery Mobile应用程序的过程中,并且不断看到旧版本的代码弹出并尝试执行。 Maybe it's because I used data-dom-cache="true" in some places? 也许是因为我在某些地方使用了data-dom-cache =“ true”? I've restarted my web server, but that doesn't fix it. 我已经重新启动了Web服务器,但是并不能解决问题。 Any ideas? 有任何想法吗?

You can use some JavaScript to find your element in the DOM Cache and delete it from there :- 您可以使用一些JavaScript在DOM缓存中找到您的元素,然后从其中删除它:-

$.domCache('#foo').remove();

Where #foo is the id of the your object. 其中#foo是您的对象的ID。

I don't believe (although could be mistaken) that there is't a .clear function, so you'd need to loop through all existing elements previously cached for you. 我不相信(尽管可能会犯错误)没有.clear函数,因此您需要遍历先前为您缓存的所有现有元素。

$.domCache doesn't work for me, but I came up with other solution: $ .domCache对我不起作用,但是我想出了其他解决方案:

function clearjQueryCache(){
    for (var x in jQuery.cache){
        delete jQuery.cache[x];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM