1

私は jQuery と jQuery Mobile をまったく使用したことがなく、問題に遭遇しました。2 つの HTML ページがあり、そのうちの 1 つはアイテムのリストです。各項目はメイン ページにリンクし、URL に ?id=xxx を追加します。メイン ページは 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 に答える