<html>
<head>
<title>js 下拉框</title>
<script language="
javascript">
function add(){
//下拉框对象
var obj=document.myform.cats;
//创建一个option标签
var japan=document.createelement("option");
//将从
文本框获取的值赋予下拉框对象的text属性,而不是value属性
japan.text=document.myform.car.value;
//调用下拉框对象的add方法来增加一个下拉项
document.myform.cats.add(japan);
//select对象的长度
alert(obj.length);
//被选择的项的索引
alert(obj.selectedindex);
//被选中的项的value值
alert(obj.value);
}
</script>
</head>
<body>
<table align="center">
<form name="myform">
<select name="cats" size="1">
<option value="我是一辆宝马车" selected="selected">宝马
<option value="2">奔驰
<option value="3">奥迪
</select>
<br>
<input type="text" name="car">
<br>
<input type="button" value="添加一个新的品牌" onclick="add()"></option>
</form>
</table>
</body>
</html>
<html>
<head>
<title>省市级联_www.jb200.com</title>
<script language="javascript">
function changecity(){
var province=document.myform.province.value;
switch(province){
case "sichuan":
newoption1=new option("成都市","chengdu");
newoption2=new option("泸州市","luzhou");
break;
case "shangdong":
newoption1=new option("青岛市","qingdao");
newoption2=new option("烟台市","yantai");
break;
case "hubie":
newoption1=new option("武汉市","wuhan");
newoption1=new option("襄樊市","wuhan");
}
//option的数组
document.myform.selcity.length=0;
//与select的对象的add()方法实现同样的功能
document.myform.selcity.add(newoption1);
document.myform.selcity.add(newoption2);
}
</script>
</head>
<body>
<form name="myform">
<table align="center">
<tr>
<td>姓名:</td>
<td><input type="text" /></td>
</tr>
<tr>
<td>省份:</td>
<td>
<select name="province" onchange="changecity()">
<option>请选择省份</option>
<option value="sichuan">四川</option>
<option value="shangdong">山东</option>
<option value="hubie">湖北</option>
</select>
</td>
<tr>
<td>城市:</td>
<td>
<select name="selcity">
<option>请选择城市</option>
</select>
</td>
</tr>
</tr>
</table>
</form>
</body>
</html>