说明:页面有一组单选按钮radio,现在页面发送请求得到一组json数据,包括radio的值。

需要根据JSON中的值绑定radio的选中状态>


<table class="table" id="attachTable">
<tbody>
<!-- A.生產良率 是否達標 -->
<tr>
<th>A.生產良率 是否達標</th>
<th><label class="radio-inline"> <input type="radio"
name="buildYieldIsOk" value="1"> 是
</label></th>
<th><label class="radio-inline"> <input type="radio"
name="buildYieldIsOk" value="0" checked="checked"> 否
</label></th>
<th><a class="op" data-type="buildYield">上傳</a></th>
<th><a class="attach" id="buildYield"></a></th>
<th><a class="delete" id="1"></a></th>
</tr>
<!-- B.NPI build Issue Summary 有無異常 -->
<tr>
<th>B.NPI build Issue Summary 有無異常</th>
<th><label class="radio-inline"> <input type="radio"
name="isHasBuildIssue" value="1"> 是
</label></th>
<th><label class="radio-inline"> <input type="radio"
name="isHasBuildIssue" value="0" checked="checked"> 否
</label></th>
<th><a id="viewBuildIssueA">查看</a></th>
<th></th>
</tr>
<!-- C.NPI test Issue Summary 有無異常 -->
<tr>
<th>C.NPI test Issue Summary 有無異常</th>
<th><label class="radio-inline"> <input type="radio"
name="isHasTestIssue" value="1"> 是
</label></th>
<th><label class="radio-inline"> <input type="radio"
name="isHasTestIssue" value="0" checked="checked"> 否
</label></th>
<th><a id="viewTestIssueA">查看</a></th>
<th></th>
</tr>
<!-- D.DFM Summary 有無異常 有上传 -->
<tr>
<th>D.DFM Summary 有無異常</th>
<th><label class="radio-inline"> <input type="radio"
name="dfmIsOk" value="1"> 是
</label></th>
<th><label class="radio-inline"> <input type="radio"
name="dfmIsOk" value="0" checked="checked"> 否
</label></th>
<th><a class="op" data-type="dfm">上傳</a></th>
<th><a class="attach" id="dfm"></a></th>
<th><a class="delete" id="2"></a></th>
</tr>
<!-- E.DFT Summary 有無異常 有上传 -->
<tr>
<th>E.DFT Summary 有無異常</th>
<th><label class="radio-inline"> <input type="radio"
name="dftIsOk" value="1"> 是
</label></th>
<th><label class="radio-inline"> <input type="radio"
name="dftIsOk" value="0" checked="checked"> 否
</label></th>
<th><a class="op" data-type="dft">上傳</a></th>
<th><a class="attach" id="dft"></a></th>
<th><a class="delete" id="3"></a></th>
</tr>
</tbody>
</table>

  json数据



使用JavaScript完成,当然也可以用其他JS,VueJs等

    //radio
$("#attachTable :input").each(function(){
if (this.name in npi2mpData) {
//console.log(this.name,npi2mpData[this.name]);
$("input[name="+this.name+"]").each(function(index){
if($("input[name="+this.name+"]").get(index).value == npi2mpData[this.name] ){
$("input[name="+this.name+"]").get(index).checked = true;
}
});
}
});

效果图

根据JSON的值设置radio选中状态的更多相关文章

  1. jquery 根据值 设置radio选中

    $("[name='selector'][value='value']").prop("checked", "checked");

  2. 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选

    设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...

  3. easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...

  4. jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中

    jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...

  5. jquery根据值设置radio和select选中状态

    1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...

  6. JQuery获取select选中值和清除选中状态(转)

    1.获取值 var provinceSearch = $("#loc_province_search").find("option:selected").att ...

  7. layui动态设置checkbox选中状态

    今天在使用jquery动态设置layui的checkbox元素的选中状态时始终只能取消选中,却不能重新勾选,点击勾选则没有问题,代码如下 if (value == "true") ...

  8. layui 动态设置 checbox 选中状态

    layui复选框checkbox选中赋值,解决layui设置checbox选中不生效的问题 直接上代码 //监听指定开关 form.on('switch(dongsir)', function(dat ...

  9. jquery 根据数据库值设置radio的选中

    jsp代码: <label>性 别</label> <input type="radio" value="1" name=&quo ...

随机推荐

  1. 「Flink」使用Java lambda表达式实现Flink WordCount

    本篇我们将使用Java语言来实现Flink的单词统计. 代码开发 环境准备 导入Flink 1.9 pom依赖 <dependencies> <dependency> < ...

  2. 浅谈centos8与centos7

    距离centos8.0(现在已经更新到8.1了)的发布已经过去几个月了,作为一个刚刚接触过几个月centos的萌新来说,本文想通过实际的操作体验来说对比一下centos8代与7代 首先,centos8 ...

  3. VEH帮你定位程序崩溃地址

    之前朋友有一个服务端程序,总是受到一些人的恶意漏洞攻击,没有源代码,只好反汇编修复了漏洞,并且使用WinLicense加保护授权. 漏洞总不是一次可以修复完的,恶意攻击并没有停止,然后加了WL保护程序 ...

  4. python基础入门之一 —— 变量与运算符

    1.标识符 由数字,字母,下划线组成 不能由数字开头 不能使用内置关键字 严格区分大小 2.数据类型 数值:int (整型) float(浮点型) 布尔型:True(真) False(假) str ( ...

  5. Numerical Testing Reportes of A New Conjugate Gradient Projection Method for Convex Constrained Nonlinear Equations

    Numerical Testing Reportes of A New Conjugate Gradient Projection Method for Convex Constrained Nonl ...

  6. Navicat Premium 12永久激活

    参考:https://baijiahao.baidu.com/s?id=1644169351506023288&wfr=spider&for=pc 百度网盘:https://pan.b ...

  7. 将short类型转换为char类型

    void short2char(uint8_t *arr1, uint16_t *arr2, int len) { ; ; for (x; x < len; x++) { arr1[x++] = ...

  8. PostgreSQL内核学习笔记四(SQL引擎)

    PostgreSQL实现了SQL Standard2011的大部分内容,SQL处理是数据库中非常复杂的一部分内容. 本文简要介绍了SQL处理的相关内容. 简要介绍 SQL文的处理分为以下几个部分: P ...

  9. 【39】为什么使用卷积?(Why convolutions?)

    为什么使用卷积?(Why convolutions?) 我们来分析一下卷积在神经网络中如此受用的原因,然后对如何整合这些卷积,如何通过一个标注过的训练集训练卷积神经网络做个简单概括.和只用全连接层相比 ...

  10. Selenium实战(四)——unittest单元测试2(断言方法+discover()多测试用例的执行)

    一.断言方法 方法 检查 版本 assertEqual(a,b) a==b   assertNotEqual(a,b) a!=b   assertTrue(x) bool(x) is True   a ...