Jquery 中 $('obj').attr('checked',true)失效的几种解决方案
转载自:搜狐博客 大拙无为
1、$('obj').prop('checked',true)
2、
$(':checkbox').each(function(){
this.checked=true;
})
为什么:attr为失效?
因为checked属于为原型对象的属性。而attr在remove原型对象时会出错。原型对象指的是自身自带的,无法移除。prop会忽略这个错误。而attr操作的是普通非原型对象(可移除)。js 的dom对象属性是可以随意增加的。
删除改属性可用removeProp()方法或将ture置为false。
Jquery 中 $('obj').attr('checked',true)失效的几种解决方案的更多相关文章
- jquery checkbox反复调用attr('checked', true/false)只有第一次生效 Jquery 中 $('obj').attr('checked',true)失效的几种解决方案
1.$('obj').prop('checked',true) 2. $(':checkbox').each(function(){ this.checked=true; }) 为什么:attr为失效 ...
- jquery checkbox反复调用attr('checked', true/false)只有第一次生效
/** * 全选 */ function checkAll() { $("input[name=ids]").attr("checked", true); } ...
- checkbox反复调用attr('checked', true/false)只有第一次生效
/** * 全选 */ function checkAll() { $("input[name=ids]").attr("checked", true); } ...
- 用$("...").attr("checked", true)设置勾选无效的原因
如下图所示,本来想要实现如下图所示的功能,于是我本来是使用$("...").attr("checked", true/false)来实现该功能,但是第一次点击时 ...
- jquery prop('checked', true)解决attr('checked', true)不能选中radio问题
正如标题所言,使用:prop('checked', true)就可以了
- angularjs中使用锚点,angular路由导致锚点失效的两种解决方案
壹 ❀ 引 公司新项目开发中,首页要做个楼层导航效果(如下图),要求能点击图标对应跳到楼层即可,因为不需要跳转过度动画,也要求最好别用JQ,想着原生js操作dom计算top的兼容性,想着用锚点实现算 ...
- jquery on事件在IE8下失效的一种情况,及解决方法/bootstrap空间绑定控件事件不好用
同事在复制bootstrap中的select控件之后,发现用$('.selectpicker').selectpicker();刷新下拉框控件不好使,后来发现是用原生js克隆的方法obj.cloneN ...
- 转:js点击事件在ios中失效的3种解决方案
ios中不允许将点击事件绑定在document或者body上,如果绑定上的话将会失效.解决方案: 例如: $(document).on('click', '#generate', function ...
- jQuery 操作复选框(checkbox) attr checked不起作用
参考资料 http://www.paobuke.com/develop/javascript/pbk849.html 这天用到jQuery功能,想实现一个简单的复选框动态全选或全不选,结果测试发现 ...
随机推荐
- UILabel自适应高度和自动换行
码: //初始化label UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)]; //设置自动行数与字符换行 [l ...
- JavaWeb学习笔记--跳转方法小结
服务端跳转:1. RequestDispatcher.forward() public void doGet(HttpServletRequest request, HttpServletRespo ...
- 字符串时间日期转为Date格式和long格式
public static Long compare_date(String DATE1, String DATE2) { DateFormat df = new SimpleDateFormat(& ...
- InputStream转为byte数组
InputStream is = request.getSession().getServletContext().getResourceAsStream("/WEB-INF/swdjzbg ...
- cf B. Permutation
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ...
- 硬盘安装windows7
微软已经发表声明 Windows XP 操作系统将于2014年4月8日停止提供补丁和安全更新,提醒用户尽快升级现有的XP操作系统.Windows XP曾在2001年10月25日正式发布的,已经走过了十 ...
- leetcode_question_112 Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- 基本SQL练习题--选课经典例题
为管理岗位业务培训信息,建立3个表: S (S#,SN,SD,SA) S#,SN,SD,SA 分别代表学号.学员姓名.所属单位.学员年龄 C (C#,CN ) C#,CN 分别代表课程编号.课程名称 ...
- c指针点滴5-指针变量计算
//接口dll _declspec(dllexport) void go() { char *p1; int *p2; p1 = (char*)0x30fa83;//每次运行exe的时候输出地址值不同 ...
- poj 2049 Let it Bead(polya模板)
Description Cannery Row percent of the target audience insists that the bracelets be unique. (Just ...