如何在不在jquery中创建文本框的情况下显示<input type =''text'>?

Sau*_*mil 0 html javascript jquery

我有一个评论框(textarea),用户在其中键入内容,当他点击进入时,该内容会自动显示在"评论部分"中.现在,当用户点击提交时,我正在执行以下代码,

var comment = $("#commentBox").val();
var commentSection = $("#commentSection");
comment.appendTo(commentSection);
Run Code Online (Sandbox Code Playgroud)

通过上面的代码,用户输入的注释动态显示在commentSection.这工作正常,但当用户输入类似的东西,

<input type='text'>
Run Code Online (Sandbox Code Playgroud)

在评论框中,然后在评论部分中创建一个文本框.那么我有没有办法让这种情况发生呢?提前致谢.

Kar*_*urg 6

一种方法是将数据附加为 .text

像这样的东西:

var comment = $("#commentBox").val();
var commentSection = $("#commentSection");
commentSection.text(comment);
Run Code Online (Sandbox Code Playgroud)

编辑:要附加到评论的现有部分,请替换:

commentSection.text(comment);
Run Code Online (Sandbox Code Playgroud)

有:

commentSection.text(commentSection.text() + comment);
Run Code Online (Sandbox Code Playgroud)