求JS控制复选框可选的种类和数量的代码.
有三个要求:选择一个复选框之后,其他不同类的复选框变成不可选。(比如选择城市和国家)选择两个复选框之后,其他复选框全都不可选。提交按钮不可用,只有在选择两个复选框以后才可...
有三个要求:
选择一个复选框之后,其他不同类的复选框变成不可选。 (比如选择城市和国家)
选择两个复选框之后,其他复选框全都不可选。
提交按钮不可用,只有在选择两个复选框以后才可以点击。
求大神留意一下!多谢! 展开
选择一个复选框之后,其他不同类的复选框变成不可选。 (比如选择城市和国家)
选择两个复选框之后,其他复选框全都不可选。
提交按钮不可用,只有在选择两个复选框以后才可以点击。
求大神留意一下!多谢! 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
展开全部
<html>
<head>
<script src="jquery.js"></script><!--请留意jQuery.js路径-->
<script language="javascript">
$(document).ready(function(){
//表单1的操作
$("form#f1").click(function(){
if($("input#A").is(":checked"))
{
$("input#D").attr("disabled","true");
$("input#B").attr("disabled","true");
$("input#C").attr("disabled","true");
}
else if($("input#B").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#D").attr("disabled","true");
$("input#C").attr("disabled","true");
}
else if($("input#C").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#D").attr("disabled","true");
$("input#B").attr("disabled","true");
}
else if($("input#D").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#B").attr("disabled","true");
$("input#C").attr("disabled","true");
}
if(!($("[name='same']").is(":checked")))
$("[name='same']").removeAttr("disabled");
})
//表单2的操作,与表单1相同
$("form#f2").click(function(){
if($("input#A1").is(":checked"))
{
$("input#D1").attr("disabled","true");
$("input#B1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
else if($("input#B1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#D1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
else if($("input#C1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#D1").attr("disabled","true");
$("input#B1").attr("disabled","true");
}
else if($("input#D1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#B1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
if(!($("[name='same1']").is(":checked")))
$("[name='same1']").removeAttr("disabled");
})
//提交按钮屏蔽条件
$("form").click(function(){
if(!($("[name='same']").is(":checked") && $("[name='same1']").is(":checked")) )
$("button#ti_jiao").attr("disabled","true");
else
$("button").removeAttr("disabled");
})
})
</script>
</head>
<body>
<form action="#" id="f1" style=" text-align:center">
<input type="checkbox" name="same" id="A"/>A
<input type="checkbox" name="same" id="B"/>B
<input type="checkbox" name="same" id="C"/>C
<input type="checkbox" name="same" id="D"/>D
</form>
<form action="#" id="f2" style=" text-align:center">
<input type="checkbox" name="same1" id="A1"/>A1
<input type="checkbox" name="same1" id="B1"/>B1
<input type="checkbox" name="same1" id="C1"/>C1
<input type="checkbox" name="same1" id="D1"/>D1
</form>
<p align="center"><button id="ti_jiao" disabled>SUBMIT</button></p>
</body>
</html>
<head>
<script src="jquery.js"></script><!--请留意jQuery.js路径-->
<script language="javascript">
$(document).ready(function(){
//表单1的操作
$("form#f1").click(function(){
if($("input#A").is(":checked"))
{
$("input#D").attr("disabled","true");
$("input#B").attr("disabled","true");
$("input#C").attr("disabled","true");
}
else if($("input#B").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#D").attr("disabled","true");
$("input#C").attr("disabled","true");
}
else if($("input#C").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#D").attr("disabled","true");
$("input#B").attr("disabled","true");
}
else if($("input#D").is(":checked"))
{
$("input#A").attr("disabled","true");
$("input#B").attr("disabled","true");
$("input#C").attr("disabled","true");
}
if(!($("[name='same']").is(":checked")))
$("[name='same']").removeAttr("disabled");
})
//表单2的操作,与表单1相同
$("form#f2").click(function(){
if($("input#A1").is(":checked"))
{
$("input#D1").attr("disabled","true");
$("input#B1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
else if($("input#B1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#D1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
else if($("input#C1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#D1").attr("disabled","true");
$("input#B1").attr("disabled","true");
}
else if($("input#D1").is(":checked"))
{
$("input#A1").attr("disabled","true");
$("input#B1").attr("disabled","true");
$("input#C1").attr("disabled","true");
}
if(!($("[name='same1']").is(":checked")))
$("[name='same1']").removeAttr("disabled");
})
//提交按钮屏蔽条件
$("form").click(function(){
if(!($("[name='same']").is(":checked") && $("[name='same1']").is(":checked")) )
$("button#ti_jiao").attr("disabled","true");
else
$("button").removeAttr("disabled");
})
})
</script>
</head>
<body>
<form action="#" id="f1" style=" text-align:center">
<input type="checkbox" name="same" id="A"/>A
<input type="checkbox" name="same" id="B"/>B
<input type="checkbox" name="same" id="C"/>C
<input type="checkbox" name="same" id="D"/>D
</form>
<form action="#" id="f2" style=" text-align:center">
<input type="checkbox" name="same1" id="A1"/>A1
<input type="checkbox" name="same1" id="B1"/>B1
<input type="checkbox" name="same1" id="C1"/>C1
<input type="checkbox" name="same1" id="D1"/>D1
</form>
<p align="center"><button id="ti_jiao" disabled>SUBMIT</button></p>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询