<!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>test</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<script language=javascript>
ie = (document.all)? true:false
if (ie){
function ctlent(eventobject){if(window.event.keyCode==13){this.document.goCar.submit();}}
}
</script>
<body onKeyDown="ctlent();">
<center>
<form action="go.asp" method="post" name="goCar">
<div class="k514" style="margin-top:20px;"> <span class="left">
<SELECT class="zt14 k100" id=firstChoice name=firstChoice onChange="selectChange(this, goCar.secondChoice, arrItems1, arrItemsGrp1);">
<option value="0" selected>-选择城市-</option>
<option value="0">安徽</option>
<option value="1"> ├合肥</option>
<option value="2"> ├芜湖</option>
<option value="0">北京</option>
<option value="3"> ├北京</option>
<option value="0">重庆</option>
<option value="4"> ├重庆</option>
</select>
</span> <span class="left zjj14">
<SELECT class="zt14 k100" id=secondChoice name=secondChoice onChange="selectChange(this, goCar.thirdChoice, arrItems2, arrItemsGrp2);">
<option selected value="0">-选择用途-</option>
</select>
</span><span class="left zjj14">
<SELECT id=thirdChoice name=thirdChoice onKeyDown="ctlent();">
<option selected value="0" class="zt14 k100">-选择车型-</option>
</select>
</span><span class="left zjj14">
<SCRIPT LANGUAGE="javascript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array(); /*arrItems1[1] = "轿车";
arrItemsGrp1[1] = 1;*/
arrItems1[2] = "本田";
arrItemsGrp1[2] = 2;arrItems1[3] = "宝马";
arrItemsGrp1[3] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array(); /*arrItems2[2] = "桑塔纳";
arrItemsGrp2[2] = 1;*/arrItems2[10] = "aa";
arrItemsGrp2[10] = 2;arrItems2[11] = "oo";
arrItemsGrp2[11] = 3;
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=goCar.thirdChoice.options.length;q>=0;q--) goCar.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
//myEle = document.createElement("option") ;
//myEle.value = 0 ;
//myEle.text = "-快速选择-" ;
document.goCar.secondChoice.options[0] = new Option('-选择用途-','0');
document.goCar.thirdChoice.options[0] = new Option('-选择车型-','0');
if(goCar.firstChoice.value==0 ){
alert("请选择省会中的城市.");
} //controlToPopulate.add(myEle) ;
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
<input type="image" src="img_zl/cx.jpg" width="56" height="22" />
</span></div>
</form>
</center>
</body>
</html>
这是文件的源码,现在我让firstChoice值不等于0时才把secondChoice的数据全部打印出来,如果条件不成立也就是firstChoice值为0时secondChoice和thirdChoice值也为零,且不打印相关数据
注:secondChoice和thirdChoice的值是相关联的,thirdChoice数据的呈现是根据secondChoice所给的值来决定的
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>test</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<script language=javascript>
ie = (document.all)? true:false
if (ie){
function ctlent(eventobject){if(window.event.keyCode==13){this.document.goCar.submit();}}
}
</script>
<body onKeyDown="ctlent();">
<center>
<form action="go.asp" method="post" name="goCar">
<div class="k514" style="margin-top:20px;"> <span class="left">
<SELECT class="zt14 k100" id=firstChoice name=firstChoice onChange="selectChange(this, goCar.secondChoice, arrItems1, arrItemsGrp1);">
<option value="0" selected>-选择城市-</option>
<option value="0">安徽</option>
<option value="1"> ├合肥</option>
<option value="2"> ├芜湖</option>
<option value="0">北京</option>
<option value="3"> ├北京</option>
<option value="0">重庆</option>
<option value="4"> ├重庆</option>
</select>
</span> <span class="left zjj14">
<SELECT class="zt14 k100" id=secondChoice name=secondChoice onChange="selectChange(this, goCar.thirdChoice, arrItems2, arrItemsGrp2);">
<option selected value="0">-选择用途-</option>
</select>
</span><span class="left zjj14">
<SELECT id=thirdChoice name=thirdChoice onKeyDown="ctlent();">
<option selected value="0" class="zt14 k100">-选择车型-</option>
</select>
</span><span class="left zjj14">
<SCRIPT LANGUAGE="javascript">
<!-- Begin
var arrItems1 = new Array();
var arrItemsGrp1 = new Array(); /*arrItems1[1] = "轿车";
arrItemsGrp1[1] = 1;*/
arrItems1[2] = "本田";
arrItemsGrp1[2] = 2;arrItems1[3] = "宝马";
arrItemsGrp1[3] = 3;
var arrItems2 = new Array();
var arrItemsGrp2 = new Array(); /*arrItems2[2] = "桑塔纳";
arrItemsGrp2[2] = 1;*/arrItems2[10] = "aa";
arrItemsGrp2[10] = 2;arrItems2[11] = "oo";
arrItemsGrp2[11] = 3;
function selectChange(control, controlToPopulate, ItemArray, GroupArray)
{
var myEle ;
var x ;
// Empty the second drop down box of any choices
for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
if (control.name == "firstChoice") {
// Empty the third drop down box of any choices
for (var q=goCar.thirdChoice.options.length;q>=0;q--) goCar.thirdChoice.options[q] = null;
}
// ADD Default Choice - in case there are no values
//myEle = document.createElement("option") ;
//myEle.value = 0 ;
//myEle.text = "-快速选择-" ;
document.goCar.secondChoice.options[0] = new Option('-选择用途-','0');
document.goCar.thirdChoice.options[0] = new Option('-选择车型-','0');
if(goCar.firstChoice.value==0 ){
alert("请选择省会中的城市.");
} //controlToPopulate.add(myEle) ;
for ( x = 0 ; x < ItemArray.length ; x++ )
{
if ( GroupArray[x] == control.value )
{
myEle = document.createElement("option") ;
myEle.value = x ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}
}
}
// End -->
</script>
<input type="image" src="img_zl/cx.jpg" width="56" height="22" />
</span></div>
</form>
</center>
</body>
</html>
这是文件的源码,现在我让firstChoice值不等于0时才把secondChoice的数据全部打印出来,如果条件不成立也就是firstChoice值为0时secondChoice和thirdChoice值也为零,且不打印相关数据
注:secondChoice和thirdChoice的值是相关联的,thirdChoice数据的呈现是根据secondChoice所给的值来决定的
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货