目前最棘手的问题是:ajax读取后台省市数据后写入到前台select标签中形成相应的option
我可以获取任意option的文本值却不能获取option的value值!
很是不解!
获取select中option-value值的代码肯定没问题!
下面是我的代码
<body onload="pro()">
省市:
<select name="province"
<option value="1">
北京市
</option>
</select><br>
城市/区县:
<select name="city">
<option value="1">
朝阳区
</option>
</select>
</body>var req=null; function pro(){ req=new ActiveXObject("Microsoft.XMLHTTP"); req.onreadystatechange = call1; req.open("get","ajax","false"); req.send(null); } function call1(){ var province=document.all("province"); if(req.readystate==4){ var dis=req.responseText; for(var i=province.options.length;i>=0;i--){ province.options.remove(i) } var arr=dis.split(","); for(var i=0;i<arr.length;i++){ var newoption = document.createElement("OPTION"); province.options.add(newoption); newoption.innerText=arr[i]; newoption.Value=i+1; } } }