2013-05-02 29 views
0

我有ID的列表,並在頁面元素上最近點擊的價值被點擊的ID的時候,我有一些代碼,就會將該id的值:獲取使用jQuery

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

我怎麼能這樣做,在jQuery中,每當用戶進入頁面時點擊了每個id?另外,頁面不刷新,它使用jQuery和Json。

+0

你的意思是每一個*號*點擊?你的意思是記錄點擊*指定了id屬性的所有元素*? – techfoobar 2013-05-02 02:10:38

+0

其次,在上面的代碼中沒有任何* id *相關。 '.'選擇器用於按類名選擇。 – techfoobar 2013-05-02 02:11:15

+0

是的,我知道。每個ID都有.show編輯器,因爲它是類。通過ID,我的意思是一個對象的ID。 – 2013-05-02 02:45:16

回答

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 
}) 
+0

我想要一個用戶進入頁面後用戶點擊的ID列表。 – 2013-05-02 02:56:05

+0

感謝您的幫助。 – 2013-05-02 18:14:19

0

試試這個:

var id; 
$("*").click(function(){ 
    id= $(this).attr("id"); 
})