读书人

控制form中两个check不能同时选择解决

发布时间: 2012-03-28 15:40:03 作者: rapoo

控制form中两个check不能同时选择
<form name= "form1 " method= "post " action= "aaaa.asp ">
<input name= "cancel_time " type= "checkbox " id= "cancel_time ">
是否改截止时间
<input name= "cancel_time2 " type= "checkbox " id= "cancel_time2 ">
是否改截止日期时间
<input type= "button " name= "Button " value= " 更 新 " class= "crystal " onClick= "javascript:submit_confirm(); ">
</form>

function submit_confirm() {
if(form1.endcancal_time.checked==true &&form1.endcancal_time2.checked==true){
alert( "“是否改截止日期”和“是否改截止日期时间”不能同时选择! ");
return false;
}
else
{
document.form1.submit();
}
}

endcancal_time和endcancal_time2可以同时不选,可以任选一个,但不能同时选,我用上面的函数控制,没起到作用,请大家指点一下

[解决办法]
<form action= " " method= "post " name= "form1 ">
<input id= "cancel_time " name= "cancel_time " type= "checkbox ">
是否改截止时间
<input id= "cancel_time2 " name= "cancel_time2 " type= "checkbox ">
是否改截止日期时间
<input class= "crystal " name= "Button " onclick= "javascript:submit_confirm(); " type= "button "
value= " 更 新 ">
</form>
<script>
function submit_confirm() {
if(document.getElementById( 'cancel_time ').checked == true && document.getElementById( 'cancel_time2 ').checked == true){
alert( "“是否改截止日期”和“是否改截止日期时间”不能同时选择! ");
return false;
}
else
{
document.form1.submit();
}
}
</script>
[解决办法]
不管需求了,LZ 自己看着办,写个通用的

L@_@K


<!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>
<title> selecte single checkbox </title>
<meta name= "generator " content= "editplus " />
<meta name= "author " content= "yixianggao " />
<meta name= "keywords " content= "javascript " />
<meta name= "description " content= "for csdn " />
</head>

<body>
<form name= "form1 " method= "post " action= "aaaa.asp ">
<h4> 根本无需脚本!杀鸡焉用牛刀! </h4>
<input type= "radio " name= "modifyList " id= "radOption1 "> <label FOR= "radOption1 "> 是否改截止时间 </label>
<input type= "radio " name= "modifyList " id= "radOption2 "> <label FOR= "radOption2 "> 是否改截止日期时间 </label> <br /> <br />
<h4> 用一下下牛刀! </h4>
<span id= "spaModifyList ">


<!-- 不要再放其他 type 的 input -->
<input type= "checkbox " id= "chbOption1 " /> <label FOR= "chbOption1 "> 是否改截止时间 </label>
<input type= "checkbox " id= "chbOption2 " /> <label FOR= "chbOption2 "> 是否改截止日期时间 </label>
<input type= "checkbox " id= "chbOption3 " /> <label FOR= "chbOption3 "> 再多也不怕,哈 </label>
</span>
<input type= "button " name= "Button " value= " 更 新 " class= "crystal " >
<script type= "text/javascript ">
<!--
var oContainer = document.getElementById( "spaModifyList ");
oContainer.selectedId = " ";
var oOptions = oContainer.getElementsByTagName( "input ");

for (var i=0; i <oOptions.length; i++)
{
oOptions[i].onclick = function ()
{
if (oContainer.selectedId != " ")
{
var selectedOption = document.getElementById(oContainer.selectedId);
selectedOption.checked = false;
}

oContainer.selectedId = this.id;
this.checked = true;
};
}
//-->
</script>
</form>
</body>
</html>

[解决办法]
厄~~

还是脚本......

<input type= "radio " onclick= "this.checked = !this.checked "> 111

哎~
具体问题,具体分析~
[解决办法]
如此简单


<!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 " />
<title> 只能选择一个check </title>

<script language= "javascript " type= "text/javascript ">

</script>
</head>

<body>
<form id= "hf ">
<input id= "c1 " type= "checkbox " onclick= "this.checked==true?hf.c2.disabled=true:hf.c2.disabled=false; " />

<input id= "c2 " type= "checkbox " onclick= "this.checked==true?hf.c1.disabled=true:hf.c1.disabled=false; " />

</form>
</body>
</html>

读书人网 >JavaScript

热点推荐