jquery-1.10.2 获取checkbox的checked属性总是undefined

       项目中用的jquery-1.10.2 需要检测一个checkbox的选中状态,想当然的用 .attr("checked") ,结果发现,无论是否选中,这个值都是 undefined 未定义。

       查找资料,特此记录:

       jq官网说明:

      As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop()method.

       .attr() 不能用于普通对象,数组,窗口,文档等,要重新获取改变dom属性,用.prop()方法。

        用.prop方法确实可行。

        贴一段代码如下:

       

 $('#regSubmit').click(function(){
    		 
    		 	var val = $("#reg-checkbox").prop("checked");
  
    		 	console.log(val);
    		 	
    		 	if(val =="checked" ||val==true){  
    		 		
    		 		var useremail = $("#reg-email").val();
    				var password = $("#reg-password").val();
    				
    				var psdHash = HASH.md5(password);
    		
    				AUTH.fnReg(useremail,psdHash,function(json){
    					
    					$("#login-email").attr("value",useremail);
    				});
    		 	}
    		 	else{
    		 		alert("亲,请阅读并同意 《中科甲骨云服务条款》!");
    		 	}
		 });


        相关链接可见: http://my.oschina.net/cxz001/blog/111730


 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值