当前位置: 代码迷 >> Web前端 >> 复选框 浏览器兼容有关问题解决方案
  详细解决方案

复选框 浏览器兼容有关问题解决方案

热度:425   发布时间:2014-01-05 18:22:55.0
复选框 浏览器兼容问题解决方案
需求,会员注册,勾选统一注册协议复选框,按钮变 亮可用,
不勾选时 变灰不可用,以下是解决方案及原理:



ie7 及以下版本 --> alert(typeof($("#agree").attr("checked")));返回的是boolean类型

ie8 --> alert(typeof($("#agree").attr("checked"))); 如果没有勾选,提示undefined
       勾选之后提示 string

ie9 或者以上版本 --> alert(typeof($("#agree").attr("checked"))); 均返回string类型
        alert($("#agree").attr("checked"));勾选时返回 checked




agree 复选框ID
toubiao_submit 按钮ID


function agree_change(){
		//IE8 或以上版本浏览器
		if(typeof($("#agree").attr("checked"))=="undefined" || typeof($("#agree").attr("checked"))=="string"){
			if(typeof($("#agree").attr("checked"))=="undefined")
			{
				$("#agree").attr("checked","checked");
				$("#toubiao_submit").attr("disabled",false);
		  		$("#toubiao_submit").removeClass("toubiao_btn_disable");
		  		$("#toubiao_submit").addClass("toubiao_btn_able");
			}else{
				if($("#agree").attr("checked")=="checked"){
					$("#agree").removeAttr("checked");
					$("#toubiao_submit").attr("disabled",true);
		  			$("#toubiao_submit").removeClass("toubiao_btn_able");
		  			$("#toubiao_submit").addClass("toubiao_btn_disable");
				}else{
					$("#agree").attr("checked","checked");
					$("#toubiao_submit").attr("disabled",false);
			  		$("#toubiao_submit").removeClass("toubiao_btn_disable");
			  		$("#toubiao_submit").addClass("toubiao_btn_able");
				}
			}
			return;
		}
		//IE7 或以下版本浏览器
		if(typeof($("#agree").attr("checked"))=="boolean"){
			if($("#agree").attr("checked"))
			{
				$("#toubiao_submit").attr("disabled",false);
		  		$("#toubiao_submit").removeClass("toubiao_btn_disable");
		  		$("#toubiao_submit").addClass("toubiao_btn_able");
			}else{
				$("#toubiao_submit").attr("disabled",true);
	  			$("#toubiao_submit").removeClass("toubiao_btn_able");
	  			$("#toubiao_submit").addClass("toubiao_btn_disable");
			}
			return;
		}
	}
  相关解决方案