将创建的元素移动到文本区域

Move element created to textarea

本文关键字:文本 区域 移动 元素 创建      更新时间:2023-09-26

我想链接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 />

只需更改textarea:

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

不能在textArea标签中放置tag

<textarea>标记定义了一个多行文本输入控件。文本区域可以容纳无限数量的字符,文本以固定宽度的字体(通常是Courier)呈现。文本区域的大小可以通过cols和rows属性来指定,甚至更好;
HTML textarea

相反,您可以将文本仅放在areatag中。

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