其中前 6 种类型为基础类型,最后 1 种为引用类型。这两者的区别在于:
基础类型的数据在被引用或拷贝时,是值传递,也就是说会创建一个完全相等的变量;
而引用类型只是创建一个指针指向原有的变量,实际上两个变量是“共享”这个数据的,并没有重新创建一个新的数据。
LZ给分吧 嘎嘎,我给你修改半天呢=================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Select2Select</TITLE>
<META content="text/htmlcharset=GBK" http-equiv=Content-Type>
</HEAD>
<BODY bgColor=#ffffff text=#000000>
<DIV align=center>
<FORM name=isc>
<TABLE border=0 cellPadding=0 cellSpacing=0>
<TBODY>
<TR align=middle>
<TD height=11 noWrap>
<SELECT name=example onchange=redirect(this.options.selectedIndex) size=1>
<OPTION selected>-</OPTION>
<OPTION value="1-1">大项1</OPTION>
<OPTION value="1-2">大项2</OPTION>
<OPTION value="1-3">大项3</OPTION>
<OPTION value="1-4">大项4</OPTION>
<OPTION value="1-5">大项5</OPTION>
<OPTION value="1-6">大项6</OPTION>
</SELECT>
<SELECT name=stage2 size=1>
<OPTION value="2-0">-</OPTION>
</SELECT>
</TD>
</TR>
</TBODY>
</TABLE>
<center>
<INPUT TYPE="button" value="Submit" onclick="javascript:alert(isc.example.value+' '+isc.stage2.value)">
</center>
</FORM>
</DIV>
<SCRIPT language=JavaScript>
<!--
var groups=document.isc.example.options.length
var group=new Array(groups)
for (i=0i<groupsi++)
group[i]=new Array()
// new Option(ViewName,OptionValue)
group[1][0]=new Option("-","-1")
group[1][1]=new Option("小项1","1")
group[1][2]=new Option("小项2","2")
group[1][3]=new Option("小项3","3")
group[1][4]=new Option("小项4","4")
group[1][5]=new Option("小项5","5")
group[2][0]=new Option("-","-1")
group[2][1]=new Option("小项1","1")
group[2][2]=new Option("小项2","2")
group[3][0]=new Option("-","-1")
group[3][1]=new Option("小项1","1")
group[3][2]=new Option("小项2","2")
group[4][0]=new Option("-","-1")
group[4][1]=new Option("小项1","1")
group[4][2]=new Option("小项2","2")
group[5][0]=new Option("-","-1")
group[5][1]=new Option("小项1","1")
group[5][2]=new Option("小项2","2")
group[6][0]=new Option("-","-1")
group[6][1]=new Option("小项1","1")
group[6][2]=new Option("小项2","2")
var temp=document.isc.stage2
function redirect(x){
for (m=temp.options.length-1m>0m--)
temp.options[m]=null
for (i=0i<group[x].lengthi++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}
//-->
</SCRIPT>
</BODY>
</HTML>
数据如果不是定死的就用ajax如果是定死的就用数据
这是我写的一个例子,数据是定死的,我这里只有两个下拉列表,三个的其实道理一样
<html>
<head>
<meta http-equiv=content-type content="text/htmlcharset=GBK">
<script language="JavaScript" type="text/javascript">
<!--
// 初始时定义相关数组
var provinces = ["吉林", "辽宁", "黑龙江", "江苏", "山东"]
var jiLin = ["长春", "吉林", "白城", "白山"]
var liaoNing = ["沈阳", "大连", "鞍山"]
var heiLongJiang = ["哈尔滨", "佳木斯", "牡丹江", "齐齐哈尔"]
var jiangSu = ["南京", "苏州", "无锡", "常州", "徐州"]
var shanDong = ["济南", "烟台", "青岛", "威海"]
var allProvinces = ["", jiLin, liaoNing, heiLongJiang, jiangSu, shanDong]
// 取得用户选择的省
function selectProvince(obj){
var province = obj.value
if(parseInt(province) >= allProvinces.length)
return
addCity(allProvinces[province])
}
// 向城市复选框中添加数据
function addCity(province){
var citys = document.all.city
citys.options.length = 1
document.all.picture.src = "images\\城市.jpg"
if(province == "") return
for(var i=0i<province.lengthi++){
citys.add(new Option(province[i], i+1, false, false))
}
}
// 选择城市列出介绍
function selectCity(obj){
var city = obj.value
document.all.picture.src = "images\\" + obj.options[parseInt(city)].text + ".jpg"
}
-->
</script>
</head>
<body>
<!--province-->
<select id="sheng" onchange="selectProvince(this)">
<option value="0" selected = true>选择省</option>
</select>
<!--city-->
<select id="city" onchange="selectCity(this)">
<option value="0" selected = true>城市</option>
</select>
<br>
<!--picture-->
<table border=15 style=border-style:ridge width=360 height=300>
<tr valign=top>
<td>
<img src="images\\城市.jpg" id="picture" name="picture" width=360 height=300/>
</td>
</tr>
</table>
<script language="JavaScript" type="text/javascript">
<!--
// 初始化省
var obj = document.all.sheng
for(i=0 i<5 i++){
obj.add(new Option( provinces[i], i + 1, false, false))
}
-->
</script>
</body>
</html>