gpt4 book ai didi

javascript - 选择选项更改时更改文本区域的值

转载 作者:行者123 更新时间:2023-12-02 17:29:49 25 4
gpt4 key购买 nike

我必须在更改选择选项时更改文本区域的内容。为此我编写了如下代码

                <tr><td>Template:</td><td>
<select t name="template" onChange = "setTemplate();">
<option value="0">Admission</option>
<option value="1">Registration</option>
<option value="2">Speech on 2,3 May</option>
</select>
</td>
<tr>
<td>Message: </td>
<td>
<textarea name="adminmessage" id="adminmessage" rows="5" cols="50"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" id="submit" value="Send SMS" class="button-primary" /></td>
</tr>
</table>
</form>
<script>
test0 = "";
test1 = "test string 1";
test2 = "test string 2";
function setTemplate() {
var otionValue = document.form.template.value;
if (otionValue == "0") {
document.form.adminmessage.value = test0;
} else if (otionValue == "1")
document.form.adminmessage.value = test1;
else if (otionValue == "2")
document.form.textarea.value = test2;
};
</script>
</div>

但这不起作用。请帮助我更正。我必须在 javascript 本身而不是 jquery 中执行此操作。

最佳答案

您的 JavaScript 语法无效。在这里检查更正的示例:http://jsfiddle.net/WkbLP/

javascript:

<script>
test0 = "";
test1 = "test string 1";
test2 = "test string 2";
function setTemplate(t) {
var otionValue = t.value;
if (otionValue == "0") {
document.getElementById('adminmessage').innerHTML = test0;
} else if (otionValue == "1")
document.getElementById('adminmessage').innerHTML = test1;
else if (otionValue == "2")
document.getElementById('adminmessage').innerHTML = test2;
};
</script>

HTML:

<select  name="template" onChange = "setTemplate(this);">
<option value="0">Admission</option>
<option value="1">Registration</option>
<option value="2">Speech on 2,3 May</option>
</select>

关于javascript - 选择选项更改时更改文本区域的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23169285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com