判断checkbox未选中状态

checkbox默认是选中状态,submit背景颜色默认是橘色,checkbox未选中时submit变灰色。 一开始用的纯css实现的,但是5s上系统版本是8.3不兼容,checkbox未选中时submit确认按钮不变色

/*.mycheck input + label + input{background: #CDCDCD;}*///是这句话不起效果,现在我还是不知道什么原因
	/*.mycheck input:checked + label + input{
		background-color: #FB793B;
	}*/

并且JS判断不管是浏览器还是手机都判断不出来

if($("input[type='checkbox']").is(':checked')=='false'){
		$("input[type='submit']").css("background","#CDCDCD");//这句判断不出来,但是true可以判断出来
	}

最终代码:

<div class="mycheck">  
		  	<input class="checkbox " type="checkbox" value="1" id="checkbox1" name="" checked="checked"/>  
		  	<label for="checkbox1"></label>
		  	获得你的公开信息(昵称 头像等)
		  	<input class="cur" type="submit" value="确认"/>
		</div> 

JS代码:

$(function () {
    $('.checkbox').on('click',function(){
	    if($(this).attr('checked')){
	        $("input[type='submit']").removeClass('cur');
	        $(this).removeAttr('checked');
	    }
	    else{
	        $("input[type='submit']").addClass('cur');
	        $(this).attr('checked','checked')
	    }
	});
});
.mycheck label{
		background-image:url(img/wopay-.png);display: inline-block;height: 36px;width: 36px; 
	    background-repeat: no-repeat;margin-bottom: -8px;margin-right: 10px;
	}
	
	.mycheck input:checked + label{  
	    background-image:url(img/wopay-OK.png);background-repeat: no-repeat;    
	}
input[type="submit"]{display:block;width: 690px;height: 86px;border: none;border-radius: 8px;text-align: center;
	font-size: 34px;line-height: 34px;-webkit-appearance: none;margin-top: 30px;-webkit-tap-highlight-color: transparent;
	background-color: #CDCDCD;color: #fff;
	}
.mycheck .cur{
		background-color: #FB793B;
	}

输入图片说明

输入图片说明

转载于:https://my.oschina.net/u/2417339/blog/868971

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值