说明:页面有一组单选按钮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. MySQL基础(4) | 视图

    MySQL基础(4) | 视图 基本语法 1.创建 CREATE VIEW <视图名> AS <SELECT语句> 语法说明如下. <视图名>:指定视图的名称.该名 ...

  2. IIS网站部署配置

    1.配置Session State

  3. 使用JAVA导出EXCEL表格(POI)

    一.POI概述 Jakarta POI 是一套用于访问微软格式文档的Java API.POI提供API给Java程序对Microsoft Office格式档案读和写的功能.在许多企业办公系统中,经常会 ...

  4. win10环境下安装mysql-8.0.18-winx64

    下载mysql安装包,然后解压到你想安装的目录下,我下载的是mysql-8.0.18-winx64 Windows 上安装 MySQL 相对来说会较为简单,最新版本可以在 MySQL 下载 中下载中查 ...

  5. 使用高精度计算斐波那契数列 c++

    使用高精度计算斐波那契数列 非高精度 Code(Non-high accuracy) 这是不用高精度的代码 #include<bits/stdc++.h> using namespace ...

  6. Vue项目中实现tab栏和步骤条的数据联动

    也就是tab栏切换步骤条随之变化 <template>   <div>     <!-- 面包屑导航  -->     <el-breadcrumb sepa ...

  7. phpcms搜索给分页代码添加参数方法

    在使用PHPCMS开发网站时遇到了一个搜索功能,需要在搜索结果分页链接上添加一些传递的参数,不然不能够正确翻页. 方法: 找到\phpcms\libs\functions\global.func.ph ...

  8. 限定输入框只能输入数字, TextBox的TextChanged事件调用

    /// <summary> /// 限定输入框只能输入数字, TextBox的TextChanged事件调用 /// </summary> /// <param name ...

  9. jQuery笔记(四)jQuery中的动画

    jQuery最吸引人的地方莫过于能做出绚丽的动画了,也是能极大提高用户体验的地方,这次我们就来一探jQuery中的动画! 一. show()方法和hide()方法 show()方法与hide()方法是 ...

  10. vs2008 asp.net “无法连接到ASP.NET Development server”

    这是因为该网站启动ASP.NET Development server时使用的端口被占用而导致的. 解决方法: 1.在“解决方案资源管理器”中选中网站项目名称,然后切换到“属性”窗口 2.在“属性”窗 ...