Store and use an array using the HTML data tag and jQuery

后端 未结 3 2072
一生所求
一生所求 2020-12-05 02:07

I am attempting to store an array in the HTML data tag. For example:

3条回答
  •  伪装坚强ぢ
    2020-12-05 02:34

    If you use valid JSON ([ and ] for the array, double quotes instead of single), like this:

    Then what you have (using .data()) to get the array will work:

    $('#locations').data('locations');
    

    You can test it here.

提交回复
热议问题