单选框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 ...
随机推荐
- eclipse + pydev 创建django项目
前提条件机器装好python,并装好django插件.(http://blog.csdn.net/lilongjiu/article/details/51405340) 1. 下载eclise Ver ...
- openssl 升级操作 -2
首先我觉得没事就用绿盟扫漏洞的公司,就是闲的蛋疼,傻逼!不少服务器使用nginx,如果openssl 是静态编译的,直接将openssl 编译到nginx里面去了,这就意味着,单纯升级openssl ...
- Docker学习(1安装docker)
1.在安装之前首先查看系统版本,ubuntu centos6 7 安装方式并不相同,所以首先确定系统版本 #cat /etc/issue 确定系统版本 2.开始安装Docker (1)Ubuntu下 ...
- 巨蟒python全栈开发flask1
1.整体把握 (1)路飞学城 - RestAPI 前后端分离开发 Django Vue.js - DRF DjangoRestFromwork - 线上商城的经验 (2)智能玩具 - RestAPI ...
- mixin 在传参中可以出现 参数 在类内部可以定义 作用域
mixin 在传参中可以出现 参数 在类内部可以定义
- an open source web server and reverse proxy
https://www.nginx.com/resources/admin-guide/ NGINX is an open source web server and reverse proxy th ...
- 什么是 C++ 11 原始字符串?
std::string path = "C:\\VulkanSDK";//需要转义 std::string path = R"(C:\VulkanSDK)";/ ...
- python模块学习(二)
configparser模块 软件常见文档格式如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLevel = 9For ...
- 我的Android进阶之旅------>Android中查看应用签名信息
一.查看自己的证书签名信息 如上一篇文章<我的Android进阶之旅------>Android中制作和查看自定义的Debug版本Android签名证书>地址:http://blog ...
- 我的Android进阶之旅------>adbd cannot run as root in production builds 的解决方法
今天用adb root命令时候,报了错误:adbd cannot run as root in production builds C:\Documents and Settings\Administ ...