如何清除 jQuery DOM 缓存?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11239540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I clear the jQuery DOM cache?
提问by Doug
How can I clear the jQuery DOM cache? 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. Maybe it's because I used data-dom-cache="true" in some places? I've restarted my web server, but that doesn't fix it. Any ideas?
如何清除 jQuery DOM 缓存?我仍在开发和测试 jQuery Mobile 应用程序,我一直看到我的代码的旧版本弹出并尝试执行。也许是因为我在某些地方使用了 data-dom-cache="true" ?我已经重新启动了我的网络服务器,但这并没有解决它。有任何想法吗?
回答by John Mitchell
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 函数,因此您需要遍历以前为您缓存的所有现有元素。
回答by DominikStyp
$.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];
}
}