调用 Web 服务后,我得到以下指定格式的 Json 响应
[{
"1": {
"value": 0.9354149103164673
},
"key": 233558146445,
"doc_count": 1
},
{
"1": {
"value": 0.9309101700782776
},
"key": 233558143870,
"doc_count": 1
},
{
"1": {
"value": 0.929838240146637
},
"key": 233558833452,
"doc_count": 1
}
]
我想显示"Key"
表格中存在的数据以及复选框,当我单击复选框时,它应该选择键值,并且该表应在单击按钮后显示为弹出窗口。
var x = [{"1":{"value":"0.9354149103164673"},"key":"233558146445","doc_count":"1"},
{"1":{"value":"0.9309101700782776"},"key":"233558143870","doc_count":"1"},
{"1":{"value":"0.929838240146637"},"key":"233558833452","doc_count":"1"}];
var tab = document.getElementById("myTable");
x.forEach(function(v,k){
var tr = document.createElement("tr");
var td = document.createElement("td");
td.innerHTML = v.key;
tr.appendChild(td);
var checkbox = document.createElement('input');
checkbox.type = "checkbox";
checkbox.name = "key";
checkbox.value = v.key;
checkbox.id = "id";
tr.appendChild(checkbox);
tab.appendChild(tr);
});
function checkValue(){
var names = document.getElementsByName("key");
names.forEach(function(v){console.log(v.value , v.checked);});
};
<table id="myTable" border="1px">
</table>
<input type="button" onclick="checkValue()" value="Check">
你可以尝试这样的事情。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句