单选框radio 选择问题
<input type="radio" name="test"/>
<input type="radio" name="test" id = "input2"/>
(说明:使用的jquery 版本是 1.10.2。)
使用 jquery 的removeAttr(),清除掉 radio 的checked属性后。使用 attr('checked',true)可以给对应的radio 附上 checked属性。但是页面展示,却没有选中。
解决方法:
使用原生js 代码实现。
var inputList = document.getElementByName("test");
for(var x=0;x<inputList.length;x++){
inputList[x].checked=false; //取消选中
}
var input = document.getElementById("input2");
input.checked = true; //选中第二个
测试是可以的。能选中,且页面能显示正确。
另外方法:
jquery1.9以后版本,attr应该不管用了,要用$(this).prop("checked", true);$(this).removeAttr("checked");选中和去除选中
$(".layui-layer-content .mjct_pjd2 .mjct_pjd3 input:radio[name=lc][value='个']").prop("checked", true);
亲测可用。
但是当"个"为变量的是后 arr[4]无法使用,因此改为以下方案,测试可以用
//选择单选框(件,套,个) arr[4]=套
var lc_arr=['件','套','个'];
var i
for(var x=0;x<lc_arr.length;x++){
if(lc_arr[x]==arr[4]){
i=x;
}
}
$(".layui-layer-content .mjct_pjd2 .mjct_pjd3 input:radio[name=lc]").eq(i).prop("checked", true);
单选框radio 选择问题的更多相关文章
- 吾八哥学Selenium(三):操作复选框checkbox/单选框radio的方法
复选框checkbox和单选框radio是web网站里经常会使用到的两个控件,那么在web自动化测试的时候如何利用Selenium来操作这俩控件呢?今天我们就来简单入门练习一下! html测试页面代码 ...
- 单选框radio改变事件详解(用的jquery的radio的change事件)
单选框radio改变事件详解(用的jquery的radio的change事件) 一.总结 1.用的jquery的radio的change事件:当元素的值发生改变时,会发生 change 事件,radi ...
- MFC学习单选框Radio使用
创建单选框Radio ,ID号IDC_RADIO_NAME 1.获取单选框内容 int RadioState = ((CButton *)GetDlgItem(IDC_RADIO_NAME))-> ...
- 自定义单选框radio样式
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- jquery单选框radio绑定click事件实现和是否选中的方法
使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1. ...
- 单选框radio总结(获取值、设置默认选中值、样式)
单选框 radio <div class="radio-inline"> <input type="radio" name="kil ...
- jquery单选框radio绑定click事件实现方法
本文实例讲述了jquery单选框radio绑定click事件实现方法.分享给大家供大家参考. 具体实现方法如下: 复制代码代码如下: <html><head><title ...
- 微信小程序:单选框radio和复选框CheckBox
单选框radio: 可以通过color属性来修改颜色. 复选框checkbox:
- 【jQuery获取下拉框select、单选框radio、input普通框的值和checkbox选中的个数】
radio单选框:name属性相同 <input type="radio" id="sp_type" name="p_type" va ...
随机推荐
- tf.name_scope()和tf.variable_scope()
https://blog.csdn.net/gqixf/article/details/80191918 https://blog.csdn.net/uestc_c2_403/article/deta ...
- SharePoint服务器端对象模型 之 访问网站和列表数据(Part 2)
(二)列表(SPList) 列表是SharePoint中最为重要的数据容器,我们一般保存在SharePoint中的所有数据,都是保存在列表中(文档库也是一种列表),因此列表对象在SharePoint的 ...
- kafka 集群安装过程
1.下载需要的安装包 http://kafka.apache.org/downloads.html 本文使用的 Scala 2.9.2 - kafka_2.9.2-0.8.2.2.tgz (asc, ...
- eclipse content assist 出现错误
解决方法是,在Window->preference->java->editor>Content Assist->advanced ,将 time out 由50 ms 改 ...
- 设置mysql外网访问
任意主机以用户root和密码mypwd连接到mysql服务器mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'myp ...
- python cookbook第三版学习笔记二十:可自定义属性的装饰器
在开始本节之前,首先介绍下偏函数partial.首先借助help来看下partial的定义 首先来说下第一行解释的意思: partial 一共有三个部分: (1)第一部分也就是第一个参数,是一个函数, ...
- COM 组件创建实例失败,原因是出现以下错误: c001f011 (Microsoft.SqlServer.ManagedDTS)
从 IClassFactory 为 CLSID 为 {AA40D1D6-CAEF-4A56-B9BB-D0D3DC976BA2} 的 COM 组件创建实例失败,原因是出现以下错误: c001f011. ...
- python 里安装 tensorflow 后运行出错的问题解决
如果出现一下错误: libcublas.so.8.0: cannot open shared object file: No such file or directory 原因是没有 cuda 环境, ...
- MCU与FPGA通信
1.MCU启动FPGA相应功能模块 通过译码器选择相应的功能模块,调用实现功能. 2.MCU与FPGA串口通信 SPI协议简单.可靠.易实现,速度快,推荐使用SPI.SPI为四线机制,包含MOSI.M ...
- C#数组学习
1.多维数组 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespa ...