用jquery将复选框改成单选框

前提是要包含jquery文件。

相关代码:

jQuery(function($) { 
    init_price_checkbox("by_price");
    init_price_checkbox("by_size");
});
function init_price_checkbox(id){
	$("#"+id+" input[type='checkbox']").each(function(){
		$(this).click(function(){
			for (var i = $("#"+id+" input[type='checkbox']").length - 1; i >= 0; i--) {
				if($(this).index("#"+id+" input[type='checkbox']")==i) 
					$(this).attr('checked','checked');
				else 
					$("#"+id+" input[type='checkbox']").eq(i).removeAttr('checked');
			};
		
		 });	
    });
}

 html代码:

<div id="by_price">
	<form id="search_by_price" method="post" action="index.php?action=search&orderby=price">
		<span class="by_words">By Price</span>
		<div class="p_left_columu">
			<div><input type="checkbox" name="75" value="1" ><span>Under $75</span></div>
			<div><input type="checkbox" name="75-100" value="2" ><span>$75 - $100</span></div>
			<div><input type="checkbox" name="100-125" value="3" ><span>$100 - $125</span></div>
		</div>
		<div class="p_right_columu">
			<div><input type="checkbox" name="125-150" value="1" ><span>$125 - $150</span></div>
			<div><input type="checkbox" name="150" value="2" ><span>$150 & Above</span></div>
		</div>
		<div class="search_button"><input type="image" border="0" οnmοuseοut="this.src='/themes/diy_html5/images/crystal_by_price/price_search.png'" οnmοuseοver="this.src='/themes/diy_html5/images/crystal_by_price/price_search_on.png'" src="/themes/diy_html5/images/crystal_by_price/price_search.png">
		</div>
	</form>
</div>

 

 

转载于:https://www.cnblogs.com/share123/p/3545318.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值