jQuery loop through data() object

后端 未结 6 586
我在风中等你
我在风中等你 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:56

    Tested with jQuery 1.4 and tips from @user292614 the following works:

    $('#mydiv').data('bar','lorem');  
    $('#mydiv').data('foo','ipsum');  
    $('#mydiv').data('cam','dolores');
    
    $.each( $('#mydiv').data(),function(i, e) {
       alert('name='+ i + ' value=' +e);
    });
    

提交回复
热议问题