如何在select中option添加复选框


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
 
<script type="text/javascript" src="../js/jquery-1.3.2.min.js"></script> 

<style>
	.outlayer{
		width:60% ; 
		height:400px;
		border:1px solid blue;  
		margin-left:20%;
		margin-right:20%;
		text-align:center
	}
	.list{
		margin-top:5px;
		margin-left:4%;
		margin-right:4%;
		float:left;
	        width:25%; 
		height:300px; 
		margin-right:50xp;
		border:1px solid red;
	}
	.title{ 
		height:30px;
		width:100%;
		background-color:#000066;
		padding-top:10px;
	 }
	.title span{  
		font-size:10xp;
		font-family:"宋体";
		color:#FFFFFF;
	}
	 
	.select{   
		width: 90%;
		height:230px;
		margin:0px 10px 10px 10px;
		text-align:left;
		border:2px solid #CCCCCC;
		overflow-y:scroll; 
		overflow-x:hidden;
		table-layout: fixed;
		word-wrap:break-word;
		word-break:break-all;
	}
 
</style>
<script>
	$(function(){
			//全选/取消全选
		 $("input[id='selectAll']").live("click",function(){ 
			 if($(this).is(':checked')){ 
			 	$(this).parent().parent().find(".select input").each(function(i){
				   		$(this).attr("checked",true);
				 }); 
			 }else{
			 	 $(this).parent().parent().find(".select input").each(function(i){
				   		$(this).attr("checked",false);
				 }); 
			 }
		});
	
	});
</script>
</head> 
<body> 
		<div class="outlayer">
			<div  class="list">
				<div class="title">
				   <span>选择快递月份信息</span> 
				</div>
				<div align="left" style="margin-left:10px;"><input type="checkbox" id="selectAll"/>全部</div>
				  
				 <div class="select" >
						<%for(int i=1;i<=12;i++){%>
							<div><input type="checkbox" value="<%=i%>" name="mouth"/><%=i%></div>
						<%}%>
				 </div>
			</div>  
		</div>
	 
</body>
</html>

效果图如下:


注意: 该方法是使用div的方式写的,因为html中有规定,select标签下的option中不能再添加其他标签,所以也无法添加复选框,因此是无法用select和option来写。

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值