模仿京东移动端筛选样式,复选框

3 篇文章 0 订阅
2 篇文章 0 订阅

直接上代码

<!DOCTYPE html>
<html>

	<head>
		<meta charset='UTF-8'>
		<title></title>
		<script type='text/javascript' src='../js/jquery-1.8.3.js'></script>
	</head>
	<style>
		.checkbox {
			width: 100px;
			height: 20px;
			background-color: #C8C7CC;
			color: #000;
			border-radius: 5px;
			margin-left: 10px;
			margin-top: 10px;
			text-align: center;
			padding: 6px;
		}
		
		.checkbox-click {
			width: 100px;
			height: 20px;
			border: 1px solid #F00;
			background-color: #FFF;
			color: #F00;
			border-radius: 5px;
			margin-left: 10px;
			margin-top: 10px;
			text-align: center;
			padding: 6px;
		}
		.checkbox p{
			margin-top: 0px;
		}
		.checkbox-click p{
			margin-top: 0px;
		}
	</style>
	<script type='text/javascript'>
		$(function() {
			no_click();
		});
		
		function no_click(){
			$('.checkbox').attr('value',false);
			$('.checkbox').click(function() {
				$("#"+this.id + " img").remove();
				var _img = document.createElement("img");
				_img.style.height = "12px";
				_img.style.float = "left";
				_img.style.marginTop = "4px"
				_img.src = "../images/tick.png";
				this.insertBefore(_img,this.childNodes[0]);  
				$(this).attr('class', 'checkbox-click') //
				$(this).attr('value',true);
				y_click();
			});
		}
		function y_click(){
			$('.checkbox-click').click(function() {
				$("#"+this.id + " img").remove();
				$(this).attr('value',false);
				$(this).attr('class', 'checkbox') //
				no_click();
			})
		}
		function trueorfalse(){
			var checkbox = $(".mui-content div")
			for (var i = 0; i < checkbox.length; i++) {
				alert(checkbox[i].getAttribute('value'));
			}
		}
	</script>

	<body>
		<div class='mui-content'>
			<div id='t' class='checkbox'>
				<p>已合格</p>
			</div>
			<div id='t1' class='checkbox'>
				<p>不合格</p>
			</div>
			<div id='t2' class='checkbox'>
				<p>未合格</p>
			</div>
		</div>
		<br />
		<button οnclick="trueorfalse()">看看选中没有</button>
	</body>
</html>

效果


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值