我正在尝试动态创建一个 JSON 数组。在站点中,有动态数量的 <div id="#selected">,我需要获取它们的所有值并创建一个 JSON 数组。
我遇到了 .push() 功能,但我无法弄清楚。
<!-- there could be a million of these, or only one... each value is unique though -->
<div id="selected" value="5|3"></div>
<div id="selected" value="3|65"></div>
function json_array_selected() {
var JSon = {};
$('div#selected').each(function() {
// let's first split the given values
var Split = $(this).attr('value');
Split = Split.split('|');
var Type = Split[0];
Value = Split[1];
// now let's set up our Json array... using the value = type way, there should never be
// any repeating
JSon.Value = Type;
});
return JSon;
}