2013-05-02 35 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"); 
})