<script type="text/javascript">
var messages = new Array();
messages[0] = "128"; //这里写入每个选项对应的说明文字
messages[1] = "108";
messages[2] = "402";
function messageReveal(str) {
var name="document.buyform.n"+str+".selectedIndex";
var messageindex = eval(name);
h = messages[messageindex];
document.buyform.y1.value = h //如果y1是变量这个要怎么写?
}
</script>
<tr>
<td><select id="n1" name="n1" OnChange="messageReveal(1)">
<option value="1">1111</option>
<option value="2">2222</option>
<option value="3">3333</option>
</select></td>
<td><input type="text" id="y1" name="y1" /></td>
<td>
<input name="x1" type="text" id="x1" /> </td>
<td> <input type="text" name="q1" /></td>
<td> <input type="text" name="p1" /></td>
</tr>
<tr>
<td><select id="n2" name="n2" OnChange="messageReveal(2)">
<option value="1">1111</option>
<option value="2">2222</option>
<option value="3">3333</option>
</select></td>
<td><input type="text" id="y2" name="y2" /></td>
<td>
<input name="x2" type="text" id="x2" /> </td>
<td> <input type="text" name="q2" /></td>
<td> <input type="text" name="p2" /></td>
</tr>
INPUT的name为变量。函数里面那句话要怎么写?
------解决方案--------------------
messageReveal(str)加个参数 试试
另外最好用document.getElementById
------解决方案--------------------
document.getElementById(id).setAttribute("name",value);