根据下拉框的当前值,来决定是单选还是复选(checkbox当radio使用)。
<script>
function uncheckAll(obj)
{
for(var i = 0;i<obj.elements.length;i++)
if(obj.elements[i].type == "checkbox")
obj.elements[i].checked = false;
}
function checkBoxValidate(cb) {
var ka=document.myform.sel.value;
if (ka<3)
{
}
else
{
for (j = 0; j < 8; j++) {
if (eval("document.myform.ckbox[" + j + "].checked") == true) {
document.myform.ckbox[j].checked = false;
if (j == cb) {
document.myform.ckbox[j].checked = true;
}
}
}
}
}
</script>
<form name=myform method="post" action="checkboxsave.asp"><div align="center">
<select name="sel" onchange="javascript:uncheckAll(document.myform)">
<option value="1" selected>请选择
<option value="2">旅行社
<option value="3">酒店
<option value="4">餐厅
<option value="5">景区
</select><br>
选框 1
<input type="checkbox" name="ckbox" value="广州" onClick="javascript:checkBoxValidate(0)">
<br>
选框 2
<input type="checkbox" name="ckbox" value="深圳" onClick="javascript:checkBoxValidate(1)">
<br>
选框 3
<input type="checkbox" name="ckbox" value="珠海" onClick="javascript:checkBoxValidate(2)">
<br>
选框 4
<input type="checkbox" name="ckbox" value="佛山" onClick="javascript:checkBoxValidate(3)">
<br>
选框 5
<input type="checkbox" name="ckbox" value="中山" onClick="javascript:checkBoxValidate(4)">
<br>
选框 6
<input type="checkbox" name="ckbox" value="清远" onClick="javascript:checkBoxValidate(5)">
<br>
选框 7
<input type="checkbox" name="ckbox" value="韶关" onClick="javascript:checkBoxValidate(6)">
<br>
选框 8
<input type="checkbox" name="ckbox" value="河源" onClick="javascript:checkBoxValidate(7)">
<br>
<input type="submit">
</div>
</form>
function uncheckAll(obj)
{
for(var i = 0;i<obj.elements.length;i++)
if(obj.elements[i].type == "checkbox")
obj.elements[i].checked = false;
}
function checkBoxValidate(cb) {
var ka=document.myform.sel.value;
if (ka<3)
{
}
else
{
for (j = 0; j < 8; j++) {
if (eval("document.myform.ckbox[" + j + "].checked") == true) {
document.myform.ckbox[j].checked = false;
if (j == cb) {
document.myform.ckbox[j].checked = true;
}
}
}
}
}
</script>
<form name=myform method="post" action="checkboxsave.asp"><div align="center">
<select name="sel" onchange="javascript:uncheckAll(document.myform)">
<option value="1" selected>请选择
<option value="2">旅行社
<option value="3">酒店
<option value="4">餐厅
<option value="5">景区
</select><br>
选框 1
<input type="checkbox" name="ckbox" value="广州" onClick="javascript:checkBoxValidate(0)">
<br>
选框 2
<input type="checkbox" name="ckbox" value="深圳" onClick="javascript:checkBoxValidate(1)">
<br>
选框 3
<input type="checkbox" name="ckbox" value="珠海" onClick="javascript:checkBoxValidate(2)">
<br>
选框 4
<input type="checkbox" name="ckbox" value="佛山" onClick="javascript:checkBoxValidate(3)">
<br>
选框 5
<input type="checkbox" name="ckbox" value="中山" onClick="javascript:checkBoxValidate(4)">
<br>
选框 6
<input type="checkbox" name="ckbox" value="清远" onClick="javascript:checkBoxValidate(5)">
<br>
选框 7
<input type="checkbox" name="ckbox" value="韶关" onClick="javascript:checkBoxValidate(6)">
<br>
选框 8
<input type="checkbox" name="ckbox" value="河源" onClick="javascript:checkBoxValidate(7)">
<br>
<input type="submit">
</div>
</form>