关于使用jquery对input中type为radio的标签checked属性的增加与移除
需求:对radio的checked属性先消除然后进行重新设置;
初步方案:
$("auForm input :radio[value='0']").removeAttr('checked');
$("auForm input :radio[value='1']").removeAttr('checked');
if(l.isover==0) $("auForm input :radio[value='0']").attr('checked','true');
if(l.isover==1) $("auForm input :radio[value='1']").attr('checked','true');
实际问题:在使用removeAttr()移除了radio的checked属性后,使用attr()重新增加不起作用;
解决方法:
$("#auForm input:radio[value='1']").removeAttr('checked');
$("#auForm input:radio[value='0']").removeAttr('checked');
if(l.isover==1) $("#auForm input:radio[value='1']").prop('checked','true');
if(l.isover==0) $("#auForm input:radio[value='0']").prop('checked','true');
即使用prop()可重新配置上该属性;
为此去查了一下关于jquery中关于attr()和prop()的使用:
从 jQuery 1.6 开始新增了一个方法 prop(),因为在 jQuery 1.6 之前,使用 attr() 有时候会出现不一致的行为。
根据官方的建议:具有 true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),其他的使用 attr(),
详情可参看该博客:http://wenzhixin.net.cn/2013/05/24/jquery_attr_prop。
关于使用jquery对input中type为radio的标签checked属性的增加与移除的更多相关文章
- jQuery对input中radio的一些操作
通过jQuery获取页面中的所有radio对象,遍历页面中的radio,取消选中的标签,因为使用到jQuery时间,因此引用到了网上公共的js,这只是本人的一些总结,大神勿喷. <html> ...
- html5中常被忘记的标签,属性
placeholder placeholder是input中的属性,就是默认输入的text,当用户输入时,text会被清空. 用法 <input type ="text" p ...
- 【】input中 type=number 去掉箭头
css中设置: input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: non ...
- 给 input 中 type="text" 设置CSS样式
input[type="text"], input[type="password"] { border: 1px solid #ccc; paddi ...
- 【转载】input 中 type='text' 的提交问题
原文链接:http://www.nowamagic.net/html/html_AboutInputSummit.php 有时候我们希望回车键敲在文本框(input element)里来提交表单(fo ...
- CSS:给 input 中 type="text" 设置CSS样式
input[type="text"], input[type="password"] { border: 1px solid #ccc; paddi ...
- jQuery设置input的type属性
$("#inputName").attr("type","text");
- 关于jQuery——attr方法和prop方法获取input的checked属性操作
经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法获取其真实值,下面介绍这两种方法的区别: 1.通过prop方法获取checked属性,获取 ...
- jquery attr方法和prop方法获取input的checked属性问题
jquery attr方法和prop方法获取input的checked属性问题 问题:经常使用jQuery插件的attr方法获取checked属性值,获取的值的大小为未定义,此时可以用prop方法 ...
随机推荐
- [转]GO err is shadowed during return
1 前言 有时候编译Go项目会出现GO err is shadowed during return的问题,是因为作用域导致变量重名,return时不是你预期的变量导致的. 2 样例 这里先复现问题,然 ...
- SpringJUnit4ClassRunner (单元测试)
1.在Maven的pom.xml中加入 <dependency> <groupId>junit</groupId> <artifactId>junit& ...
- spring+myBatis 配置多数据源,切换数据源
注:本文来源于 tianzhiwuqis <spring+myBatis 配置多数据源,切换数据源> 一个项目里一般情况下只会使用到一个数据库,但有的需求是要显示其他数据库的内容,像这样 ...
- 前端开发,走浏览器缓存真的很烦,拒绝浏览器走缓存从meta标签做起!
<meta http-equiv="Cache-Control" content="no-cache" /> <meta http-equiv ...
- CF1029A Many Equal Substrings
题目描述 你有一个字符串t,它由n个字母组成. 定义一个字符串s的子串为s[l...r],表示从位置l到r构成的一个新的串. 你的目标是构造一个字符串s,使得它的可能长度最小,要求s中存在k个位置i, ...
- python中hasattr()、getattr()、setattr()函数的使用
1. hasattr(object, name) 判断object对象中是否存在name属性,当然对于python的对象而言,属性包含变量和方法:有则返回True,没有则返回False:需要注意的是n ...
- pip 源
pip使用过程中的痛苦,大家相必都已经知道了,目前豆瓣提供了国内的pypi源,源包相对会略有延迟,但不影响基本使用. pip install some-package -i https://pypi. ...
- BootstrapTable,选中某几行,获取其数据并进行后台处理。以及其他的属性使用。
参考链接:bootstrap Table API 中文版 Bootstrap Table 选中某几行,获取其数据 Ajax传递数组,struts2接收数组 1.首先将复选框搞出来,<table ...
- Spring 源码学习系列
前言 Spring框架之于 JavaEE 程序员来说,犹如锄头之于农民.Java 程序员每天都要使用Spring框架,Spring框架也确实是个可手的工具. 最初使用Spring的时候,我们需要配置m ...
- 关于spring的自动注入
关于spring的自动注入 spring里面可以设置BeanDefinition自动注入类型,默认为AUTOWIRE_NO(不进行自动注入).mybatis里面的扫描接口生成MapperFactory ...