根据JSON的值设置radio选中状态
说明:页面有一组单选按钮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选中状态的更多相关文章
- jquery 根据值 设置radio选中
$("[name='selector'][value='value']").prop("checked", "checked");
- 设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选
设置checkbox选中,设置radio选中,根据值设置checkbox选中,checkbox勾选 >>>>>>>>>>>>&g ...
- easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
获取一组radio被选中项的值var item = $('input[@name=items][@checked]').val();获取select被选中项的文本var item = $(" ...
- jquery radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Se ...
- jquery根据值设置radio和select选中状态
1.radio选中: $("input[name=test][value=34]").attr("checked",true);//value=34的radio ...
- JQuery获取select选中值和清除选中状态(转)
1.获取值 var provinceSearch = $("#loc_province_search").find("option:selected").att ...
- layui动态设置checkbox选中状态
今天在使用jquery动态设置layui的checkbox元素的选中状态时始终只能取消选中,却不能重新勾选,点击勾选则没有问题,代码如下 if (value == "true") ...
- layui 动态设置 checbox 选中状态
layui复选框checkbox选中赋值,解决layui设置checbox选中不生效的问题 直接上代码 //监听指定开关 form.on('switch(dongsir)', function(dat ...
- jquery 根据数据库值设置radio的选中
jsp代码: <label>性 别</label> <input type="radio" value="1" name=&quo ...
随机推荐
- vue自定义分页组件---切图网
vue2.5自定义分页组件 Pagination.vue,可设置每页显示条数,带跳转框直接跳转到相应页面,亲测有用.目前很多框架自带有分页组件比如elementUI,不过在面对一个拿到PSD稿,然后重 ...
- 回炉重造之重读Windows核心编程-001-错误处理
Windows处理错误靠的是API的返回值,类型不止一种种: VOID,函数不可能失败,Windows API的返回值很少是这个情况. BOOL,如果函数失败,则返回值是0,否则返回是非零值.不要测试 ...
- 今日确定开源近两年来的EA程序
从2018年开始研究mt4的mql,在2019年主要设计了NinjaLoveFishEA这款网格程序,稳定运行了1年多,今年的伊朗被袭击,造成金价大幅上涨,-18%止损我离场后,决定不再继续研究了. ...
- 硬件知识整理part1--电阻E系列行业规范
仁者,人心也,义者,人路也. --孟子 “ E ”表示“指数间距”(Exponential Spacing) 在上个20世纪的电子管时代,电子元器件厂商为了便于元件规格的管理和选用.大规模生产的电 ...
- sql查询 ——排序
-- 排序 -- order by 排序 默认为升序 -- asc 升序 -- desc 降序 -- 查询身高 分别用升序和降序 select *from student order by high ...
- UTF-8(bom-non)
Public Sub WriteUTF_8BomNon(ByVal fileName As String, ByVal strLine As String) Dim stream: Set strea ...
- Linux配置安装
1. 安装jdk 1.1 卸载:使用java version查看虚拟机是否有jdk环境,存在先卸载: 1. 首先我的系统是CenOS7,安装完成后,先打开终端,切换到管理员账号,命令如 ...
- 清北学堂—2020.1提高储备营—Day 1 morning(模拟、枚举、搜索)
qbxt Day 1 morning --2020.1.17 济南 主讲:李佳实 目录一览 1.模拟和枚举 2.基础搜索算法(DFS.BFS.记忆化搜索)以及进阶搜索算法(纯靠自学) 总知识点:基础算 ...
- (一)Python GUI 创建及添加部件
1 开始创建Python GUI 实现代码: import tkinter as tk win = tk.Tk() win.title("Python GUI") win.main ...
- C# WPF 时钟动画(1/2)
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF 时钟动画(1/2) 内容目录 实现效果 业务场景 编码实现 本文参考 源码下载 ...