1

我对 jQuery 和 jQuery Mobile 完全陌生,并且遇到了问题。我有两个 html 页面,其中一个是项目列表。每个项目链接到主页,并添加 ?id=xxx 到 url。主页使用以下代码读取 id 并提供内容:

       $.urlParam = function(name){
   var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
   return results[1] || 0;
   }

然后我使用将 id 打印到控制台

   console.log($.urlParam('id'));

页面第一次加载 id 是正确的。当我加载列表并选择不同的项目时,URL 中的 id 会发生变化,但是与以前相同的 id 会打印到控制台并且内容不会更新。我认为这个问题可能与缓存有关。我尝试使用不同的函数(没有 RegExp)来读取 id,但它产生了同样的问题。

谢谢!

4

1 回答 1

0
Why don't you use session storage (if its a mobile website) on the click event of the list item store this selected id into session storage and on the main page live get it back from storage, so you need not pass using query string, generally passing from query string is not safe, and you have limitations on how much data you can pass.
于 2013-07-17T05:49:53.970 回答