hidden 传值

来源:百度知道 编辑:UC知道 时间:2024/06/29 02:59:00
想做一个无刷新2级下拉菜单

………………前面是定义的数组

function mychange(provalue) {
document.myform.dropcity.length = 0; //先将dropcity下拉菜单清空
document.myform.dropcity.options[0] = new Option('==请选择区县==', ''); //先添加的提示行
var i;

for (i = 0; i < subcity.length; i++) {
if (subcity[i][0] == provalue) {
//在dropcity下拉框中添加新项
document.myform.dropcity.options[document.myform.dropcity.length] = new Option(subcity[i][1], subcity[i][2]);
}
}
document.getElementsByName("abc").value=document.getElementsByName("droppro").value.text;//这句是把省的值赋值给hidden的value,貌似有错

}
</script>
</head>
<body>
<form name= "myform" medthod = "post">
<select name = "droppro" onChange = "mychange(this.options[this.selectedIndex].value);">
<option value = "">==请选择省份==</option>
<

注意这个方法document.getElementsByName里面写的是elements,也就是说返回值是一个HTML标签元素的集合,所以你那样直接使用赋值是没用的。
要选取单个元素的话,使用document.getElementById(id),比如
<select name = "droppro" id="selectDroppro" ...
<input id="HiddenValue" name="abc" ...
document.getElementById("HiddenValue").value = document.getElementById("selectDroppro").value;
这样应该就可以得到值。

document.getElementsByName("abc").value=document.getElementsByName("droppro").value.text;//这句是把省的值赋值给hidden的value,貌似有错

在IE中getElementsByName其实找的不是name而是ID。你把<select name = "droppro" onChange = "mychange(this.options[this.selectedIndex].value);">
先改成这样:<select id= "droppro" onChange = "mychange(this.options[this.selectedIndex].value);">
然后这句也换下:
document.getElementsByName("abc").value=document.getElementsByName("droppro").value//

其他地方没有错的话。应该就