我的项目需要将数组中的值从 json 分配给 和 中多个表的特定 ID。
正如您在下面看到的包含标题和赔率中的 ID 的 html。你可以看到我为这个特定的 html 写死了,因此我需要从后端检索哪些特定的标题和赔率将根据后端给定的值进行更改。
HTML
<tr><th class="GB1_0 name" id="t_B1_0" title="第一球 0"><input type="hidden" id="k_B1_0" value="BALL"><span class="b0">0</span></th>
<td class="GB1_0 odds" id="o_B1_0">9.93</td>
<td class="GB1_0 amount ha"><input name="B1_0" class="ba"></td>
</tr>
我们如何做到这一点?多多指教谢谢
最佳答案
这是您要找的吗?
<script>
$( document ).ready(function() {
var jsonObj = {
B1_0 : 9.93,
B1_1 : 9.95,
B1_2 : 9.94
};
$.each(jsonObj, function (index, value) {
console.log(index);
console.log(value);
$("#o_"+index).html(value);
});
});
</script>
关于javascript - 如何根据ID将json中的值数组分配给特定表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43692327/