jQuery loop through data() object

后端 未结 6 588
我在风中等你
我在风中等你 2020-12-04 22:28

Is it possible to loop through a data() object?

Suppose this is my code:

$(\'#mydiv\').data(\'bar\',\'lorem\');  
$(\'#mydiv\').data(\'f         


        
6条回答
  •  感情败类
    2020-12-04 22:48

    I just tried this but needed some extra data values. If you also got this "problem" then the following should work.

    $('#mydiv').data('bar', {name:'lorem', id:'156', price:'199'}); 
    

    then you can simply extend with the value id

    $.each( $('#mydiv').data(),function(i, e) {
       alert('name='+ i + ' name=' +e.name + ' id='e.id + ' price=' + e.price );
    });
    

提交回复
热议问题