创建多行textarea

时间:2017-02-03 14:57:36

标签: javascript jquery html

<!DOCTYPE html>
<html>
<body>

<p>Click the button to create a File Upload Button.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var x = document.createElement("INPUT");
    var y = document.createElement("INPUT");
    x.setAttribute("type", "textarea");
    y.setAttribute("type", "file");
    document.body.appendChild(x);
    document.body.appendChild(y);
}
</script>
</body>
</html>

请帮助我们使用与代码相同的语言创建可见的多行文本区域的代码。

3 个答案:

答案 0 :(得分:2)

textarea不是<input>的一种类型。 <textarea>是它自己的标记:

&#13;
&#13;
function myFunction() {
  var x = document.createElement("textarea");
  var y = document.createElement("INPUT");
  y.setAttribute("type", "file");
  document.body.appendChild(x);
  document.body.appendChild(y);
}
&#13;
<p>Click the button to create a File Upload Button.</p>

<button onclick="myFunction()">Try it</button>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

.createElement("INPUT")更改为.createElement("TEXTAREA")

&#13;
&#13;
function myFunction() {
    var x = document.createElement("TEXTAREA");
    var y = document.createElement("INPUT");
    y.setAttribute("type", "file");
    document.body.appendChild(x);
    document.body.appendChild(y);
}
&#13;
<p>Click the button to create a File Upload Button.</p>

<button onclick="myFunction()">Try it</button>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

Textarea元素不是输入,它们是他们自己的东西。

&#13;
&#13;
<body>

<p>Click the button to create a File Upload Button.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var x = document.createElement("TEXTAREA");
    var y = document.createElement("INPUT");
    y.setAttribute("type", "file");
    document.body.appendChild(x);
    document.body.appendChild(y);
}
</script>
</body>
</html>
&#13;
&#13;
&#13;