0

ID のリストを含むページがあり、ID をクリックすると、その ID の値を取得するコードがいくつかあります。

  $(document).on('click', '.show-editor', function(e){
  e.preventDefault();
  var editPath = $(this).find('a').attr('href');
  var jOption = $(this).text();

ユーザーがページにアクセスしてからクリックされたすべてのIDに対して、jQueryでこれを行うにはどうすればよいですか? また、ページは更新されず、jQuery と Json を使用します。

4

2 に答える 2

0

*質問を理解したので、修正された回答*

それらを保持する期間によっては、sessionStorage を使用するのが最善の策のようです。

そのようです:

$('a').on('click',function(e){
    if(typeof sessionStorge["ids"] !== "undefined"){
        sessionStorage["ids"]=sessionStorage["ids"] + ', ' + this.id; 
       // be careful that all elements have an id (or that you don't mind undefined' all through your data)
      } else {
        sessionStorage['ids']=this.id;
      }
})

次に、ユーザーがページを離れる前にすべてのデータを取得するには:

$(window).on('unload',function(e){
  var arr=sessionStorage['ids'] || '';
  arr=arr.split(',');
  // now you have an array of these ids to do with as you please
})
于 2013-05-02T02:47:53.627 に答える