请高手帮忙改一改JS函数!
以下代码的 alert()是放在 <select name= "s2 " onChange= "alert(this.value) "> ,alert()里的值是所选项的value,
但是如何写能把它写到函数changeselect1()里而不是在select的onChange里呢?
<script language= "JavaScript ">
<!--
var subcat = new Array();
subcat[0] = new Array( '商铺 ', '一线铺 ', '10000 ')
subcat[1] = new Array( '商铺 ', '二线铺 ', '20000 ')
subcat[2] = new Array( '写字楼 ', '专业写字楼 ', '30000 ')
subcat[3] = new Array( '住宅 ', '豪华住宅 ', '8000 ')
subcat[4] = new Array( '住宅 ', '普通住宅 ', '7000 ')
function changeselect1(locationid)
{
document.form1.s2.length = 0;
document.form1.s2.options[0] = new Option( '==请选择== ', ' ');
for (i=0; i <subcat.length; i++) //legth=20
{
if (subcat[i][0] == locationid) {document.form1.s2.options[document.form1.s2.length] = new Option(subcat[i][1], subcat[i][2]);}
}
}
//-->
</script>
<form name= "form1 ">
二级联动:
<select name= "s1 " onChange= "changeselect1(this.value) ">
<option> ==请选择== </option>
<option value= "商铺 "> 商铺 </option>
<option value= "写字楼 "> 写字楼 </option>
<option value= "住宅 "> 住宅 </option>
</select>
<select name= "s2 " onChange= "alert(this.value) ">
<option> ==请选择== </option>
</select>
</form>
------解决方案--------------------在changeselect1方法里加上
document.getElementsByName( "s2 ")[0].onchange=function(){
alert(this.value);
}