说明:页面有一组单选按钮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. 获取Data和Log默认路径

    使用SERVERPROPERTY()来得到Data和Log的默认路径: InstanceDefaultDataPath和InstanceDefaultLogPath分别返回默认数据和日志目录. DEC ...

  2. opencv —— minEnclosingCircle、fitEllipse 寻找包裹轮廓的最小圆、点集拟合椭圆

    寻找包裹轮廓的最小圆:minEnclosingCircle 函数 返回圆应满足:① 轮廓上的点均在圆形空间内.② 没有面积更小的满足条件的圆. void minEnclosingCircle(Inpu ...

  3. docker配置仓库源

    1 修改docker配置文件 下面的内网ip改成公司的私有仓库地址 后面两个建议保留(一个是国内加速源,一个是国外仓库.这两个删了也是可以的) 2 重启docker服务 # vim /etc/dock ...

  4. centos7 字体库。vim乱码

    centos7 字体库.vim乱码 windows上传文件到centos,需要先使用dos2unix命令进行格式转换 先查看/usr/share下有没有这两个文件 没有的话yum -y install ...

  5. NPM 包管理工具详解,使用教程

    NPM 包管理工具 1.1 定义:什么是 NPM NPM 全称 Node Package Manager,它是 JavaScript 的包管理工具, 并且是 Node.js 平台的默认包管理工具.通过 ...

  6. centos 7.6 docker 安装 nextcloud -使用sqlite数据库

    docker search nextcloud docker pull docker.io/nextcloud docker images mkdir /home/nextcloud chmod -R ...

  7. hash类型的应用场景 —— Redis实战经验

    hash类型是一个string类型的field和value的映射表,每个 hash 可以存储 232 - 1 键值对(40多亿),hash类型主要有以下应用场景. 1. 购物车 以用户id为key,商 ...

  8. H5网页布局+css代码美化

    HTML5的结构化标签,对搜索引擎更友好 li 标签对不利于搜索引擎的收录,尽量少用 banner图片一般拥有版权,不需要搜索引擎收录,因此可以使用ul + li <samp></s ...

  9. mybatis中用到的9种设计模式

    1.Builder模式:例如SqlSessionFactoryBuilder.XMLConfigBuilder.XMLMapperBuilder.XMLStatementBuilder.CacheBu ...

  10. 【剑指Offer】63、二叉搜索树的第k个结点

    题目描述 给定一棵二叉搜索树,请找出其中的第k小的结点.例如, (5,3,7,2,4,6,8) 中,按结点数值大小顺序第三小结点的值为4. 题解一:DFS 借助栈实现 // 中序非递归 public ...