将创建的元素移动到textarea

时间:2015-09-30 12:20:39

标签: javascript

我想使用第二个脚本链接2个脚本以将第一个结果发送到剪贴板。两者都有效但分开 谢谢,对不起,如果我不清楚的话。

<html>
<body>
<p>Click the button to create a h1 element with some text.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var h = document.createElement("H1");
var t = document.createTextNode("It works");
h.appendChild(t);
document.body.appendChild(h);
}
</script>

<script type="text/javascript" src="ZeroClipboard.js">
</script>

<textarea name="box-content" id="box-content" rows="10" cols="70">
Will be copied to clipboard.
Line2.
Line3.
</textarea>

<br /><br />

         

2 个答案:

答案 0 :(得分:1)

只需更改textarea的.value

 document.getElementById('box-content').value = "It works";

答案 1 :(得分:0)

您无法在tag标记中放置textArea

<textarea>标签定义了一个多行文本输入控件。文本区域可以包含无限数量的字符,文本以固定宽度字体(通常为Courier)呈现。可以通过cols和rows属性指定文本区域,甚至更好;通过CSS&#39;高度和宽度属性。
HTML textarea

相反,您只能在areatag中放置文字。

&#13;
&#13;
function myFunction() {
    //var h = document.createElement("H1");
    var t = document.createTextNode("It works");
    //h.appendChild(t);
    document.getElementById('box-content').appendChild(t);
}
myFunction();
&#13;
<textarea name="box-content" id="box-content" rows="10" cols="70"></textarea>
&#13;
&#13;
&#13;