我的textarea和它的所有属性都是正确的,但是我的javascript不对无法设置oTextbox3的值。
<html>
<head>
<title>Retrieving a Textbox Value Example</title>
</head>
<body>
<textarea rows="5" cols="25" name="txt2"></textarea> <br /> <textarea rows="5" cols="25" name="txt3"></textarea>
<br />
<input type="button" value="Set Values" onclick="setValues()" />
<script type="text/javascript">
function setValues() {
var oTextbox2= document.getElementById("txt2");
oTextbox2 = oTextbox2.value; oTextbox2 = oTextbox2.split(" ");
oTextbox2 = oTextbox2.sort();
var oTextbox3 = document.getElementById("txt3");
oTextbox3.value = oTextbox2;
}
</script>
</body>
</html>
最佳答案
您使用 document.getElementById
但将 name
分配给您的 DOM 元素。使用 id
属性代替:
<textarea rows="5" cols="25" id="txt2"></textarea> <br /> <textarea rows="5" cols="25" id="txt3"></textarea>
关于这段代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19751600/