2010-07-14 48 views

回答

0

这里是一个可以说明这样做的一种方式的示例:

<html> 
<head> 
<script> 
var messages = ['Message 0', 'Message 1', 'Message 2', 'Message 3', 'Message 4']; 
function myOnChangeHandler(selectObj) { 
    // if there are more elements with name="additional_info" then you should attach unique id to your text area and use getElementById instead 
    var textAreaElement = document.getElementsByName("additional_info")[0]; 
    textAreaElement.value = messages[selectObj.selectedIndex]; 
} 

</script> 
</head> 
<body> 
<form> 
<select id="continent" onchange="myOnChangeHandler(this);"> 
    <option value="0">Select a Continent</option> 
    <option value="1">North America</option> 
    <option value="2">South America</option> 
    <option value="3">Asia</option> 
    <option value="4">Europe</option> 
    </select> 
    Additional info: 
<textarea cols="80" rows="8" style="" name="additional_info"></textarea> 
</form> 
</body> 
<html> 

希望这有助于!

+0

这似乎已经完成了技巧谢谢,现在唯一的问题是值是字符串,它将根据错误的状态而改变。我会尝试做一个开关案例或使用elsif语句为每个状态输出正确的消息。 再次感谢 – user379222 2010-07-14 15:14:48