js的2级联动的一种方法!

  • Post author:
  • Post category:其他




<script language=”JavaScript” type=”text/javascript”>



var arrlist1=new Array(3)

arrlist1[0]=new Array(“111″,”111的只”);

arrlist1[1]=new Array(“111″,”111111”);

arrlist1[2]=new Array(“111″,”11111”);

var arrlist2=new Array(3)

arrlist2[0]=new Array(“22222″,”2222”);

arrlist2[1]=new Array(“222222″,”222”);

arrlist2[2]=new Array(“22222″,”222”);




function changlist(obj){


var arrlistid=obj.value

var arrlist=eval(“arrlist”+arrlistid)

//alert(arrlist)

var obj=document.getElementById(“b”);

//obj.options.length=0;

for (i=0;i<arrlist.length;i++){


obj.options[i]=new Option(arrlist[i][0],arrlist[i][1])

}

}


</script>


<form id=”form1″ name=”form1″ method=”post” action=””>

<select name=”a” id=”a” οnchange=”changlist(this)”>

<option value=”2″>&gt;&gt;留学</option>

<option value=”1″>&gt;&gt;移民</option>

</select>

<select name=”b” id=”b”>

<option>请选择</option>

</select>

</form>



版权声明:本文为idea888原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。