【发布时间】:2011-08-18 09:06:59
【问题描述】:
我在网页中有两个选择框(一个用于汽车类型,另一个用于汽车型号),我想使用 JavaScript 根据另一个选择框来更改其中一个。
代码示例如下:
<html>
<head>
<script type="text/javascript">
function showCarModels(CarTypeVaraiable)
{
//I want to hide all the options in the CarModelsList and select the options with name property value equals to CarTypeVaraiable Value .. How I can write this in JavaScript ?????
}
</script>
</head>
</script>
<body>
<p>Selecting Car Models depending on the Car Type Value ..... </p>
Car Type<select id="selCarType" name="selCarType" class="selCarType" size="1" onchange="showCarModels('selCarType');">
<option class="City" value="0" selected="selected">choose Car Type</option>
<option class="CarType" value="100" >Toyota</option>
<option class="CarType" value="200" >Chevrlolet</option>
<option class="CarType" value="300" >Kia</option>
</select>
Car Model
<select id="selCarModel" name="selCarModel" class="selCarModel" size="1">
<option class="City" value="0">choose Car Model</option>
<option class="CarType" value="110" name="100" title="13" >Toyota optra</option>
<option class="CarType" value="120" name="100" title="13" >Toyota Aveo</option>
<option class="CarType" value="130" name="100" title="13" >Toyota Corolla</option>
<option class="CarType" value="210" name="200" title="13" >Chevrlolet Optra</option>
<option class="CarType" value="220" name="200" title="13" >Chevrlolet Aveo</option>
<option class="CarType" value="301" name="300" title="13" >Kia Rio</option>
<option class="CarType" value="450" name="300" title="13" >Kia Optima</option>
<option class="CarType" value="600" name="300" title="13" >Kia Serato</option>
</select>
</body>
</html>
我应该在代码中写什么来实现两个下拉列表之间的这种依赖关系?
【问题讨论】:
-
嗯...
<option>上不能有名字,所以这有点棘手。
标签: javascript html function drop-down-menu onchange