我想在多个特定行中填充json数据。杰森:
{"locations":[{"Location":"27|","Name":"Al Jamia Distric B ,"branch":"23","MaleStaff":"20","FemaleStaff":"30"},{"Location":"26|","Name":"Al Kharj Branch ","branch":"146","MaleStaff":"40","FemaleStaff":"50"}]}
HTML:
<tr>
<td>
<input type="text" class="branch" value="23"/>
</td>
<td>
<input type="text" class="male"/>
</td>
<td>
<input type="text" class="female"/>
</td>
......
所以我想在雄性和雌性类中填充数据,其中“ html输入标记中的类分支值为23,它等于json中的分支值”。帮帮我
尝试将<tbody>
parent元素添加到<tr>
具有<table>
element的元素中;使用onlyfor
循环进行迭代a.locations
,input
利用[value=" + a.locations[i].Code + "]
属性选择器进行过滤; 选择.parent()
过滤的input
,.male
内元件子.next()
td
元件; .append()
a.locations[i].MaleStaff
到选定的过滤.male
元素
var a = $.parseJSON(data);
for (var i = 0; i < a.locations.length; i++) {
$("input[value=" + a.locations[i].Code + "]")
.parent().next("td").find(".male")
.append(a.locations[i].MaleStaff);
}
jsfiddle http://jsfiddle.net/vzL9mwnz/1/
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句