单击“主页”按钮时清除DOM缓存

单击“主页”按钮时清除DOM缓存,dom,caching,jquery-mobile,Dom,Caching,Jquery Mobile,我的页面顺序如下:index.html-->news.html-->newstext.html。在我的news.html页面div中,我启用了data dom cache=“true”,因为当人们从newstext返回时,他们位于相同的页面位置,并且news.html不会刷新 html有一个主页按钮,可以将其带回索引,在那里有更多的主题可以点击。单击“主页”按钮时,如何从dom中清除news.html <head> <meta charset="utf-8"/>

我的页面顺序如下:index.html-->news.html-->newstext.html。在我的news.html页面div中,我启用了data dom cache=“true”,因为当人们从newstext返回时,他们位于相同的页面位置,并且news.html不会刷新

html有一个主页按钮,可以将其带回索引,在那里有更多的主题可以点击。单击“主页”按钮时,如何从dom中清除news.html

<head>
  <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
<script>
  function clearDom(div){
    $(div).remove();}
</script>
</head>
<body>
<div data-role="page" id="mainNews" data-dom-cache="true">
  <div data-theme="b" data-role="header" data-position="fixed" data-tap-toggle="false">
    <a onclick="clearDOM('mainNews');" data-role="button" data-rel="back" data-icon="home" data-iconpos="notext" class="ui-btn-left"></a>
</div>

函数clearDom(div){
$(div.remove();}
如您所见,我尝试实现onclick方法,尝试传递此页面的divID,但没有成功。我找到的唯一主题是根本不缓存。我想缓存,直到用户离开此页面。我认为这对其他人很有帮助。谢谢你的时间

只是一个更新:在我的Android手机上,点击news.html中的链接,在“缓存进程”下,我的应用程序可以缓存20到30 MB的空间。这太多了,所以我真的需要澄清一下

试试看:

clearDOM('mainNews')

您需要ID选择器的#