说明:页面有一组单选按钮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. wordpress 配置坑详解

    首先 经过我测试,php74模块没有支持apache的.所以升级到php74 之后,php无法使用. 最基本的函数phpinfo 调用不出来,没有相关的模块. 安装mariadb 10.4 之后发现, ...

  2. 苹果Mac电脑永久路由的添加 & Mac 校园网连接教程

    学校校园网面向全校师生开放,无奈Windows用户基数大,学校只为Windows平台制作了内网连接工具,Mac平台资源较少,本人查阅相关资料后,总结整理出以下步骤,方便本校学生连接校园网.有永久路由添 ...

  3. Spring Boot 配置拦截器方式

    其实spring boot拦截器的配置方式和springMVC差不多,只有一些小的改变需要注意下就ok了.下面主要介绍两种常用的拦截器: 一.基于URL实现的拦截器: public class Log ...

  4. 教你一种简单方法给word和PDF格式的文件使用电子签名

      前言  虽然还处在非常时期,但很多公司已陆陆续续复工或准备复工.   上周,人事妹纸给了我们一份,企业员工健康情况申报表.具体如下 现在问题来了,需要本人签名,电脑打上去的不算,需要手写. 此时, ...

  5. 树莓派点亮LED灯需要几行代码?3行。小孩子都能学会

    目录 点亮LED灯 硬件连接 代码 闪烁的LED灯 呼吸灯 其他 点亮LED灯 硬件连接 找一个LED灯,连接如上图,注意长短引脚,经过这些年的狂轰乱炸,大家对于这个应该不漠视,毕竟Arduino都进 ...

  6. Win10多用户同时登陆远程桌面

    想记录一下最近解决的一些问题,发现还是博客最合适,虽然之前从来没写过,希望以后能养成这个好习惯. 家里有一台台式机装着Win10,还有一台macbook,平时遇到需要用Win系统又不想坐在书桌前时,我 ...

  7. 2.Python函数/方法(method/function)详解

    1.什么是函数 它是一段功能代码,理解为一种功能行为,在内存中有空间区域,函数需要被调用才能执行(通过函数名来调用): 好处: 1).提高代码的复用性 2).提升代码的阅读性 3).增加代码的扩展性 ...

  8. 【React Native】集成声网Agora语音通讯

    前言: 公司的产品是一款基于社交的内容聊天软件,需要集成语音通讯功能,在写iOS原生项目时,用到的就是Agora SDK,现在写React Native也直接采用了Agora的库. 集成iOS.And ...

  9. 文件下载(download) 前后台备注自用

    1.后台 1.1 ResponseBean 返回封装的格式 @Data @Accessors(chain = true) public class ResponseBean { private Str ...

  10. 剑指offer-面试题50-第一个只出现一次的字符-哈希表

    /* 题目: 求字符串第一个只出现一次的字符. */ /* 思路: 使用map遍历两次,第一次计数,第二次找到计数为1的第一个字符. */ #include<iostream> #incl ...