在我看来,我想将用户在文本区域中输入的文本添加到我的表格中。
用户在文本区域中输入文本,然后单击按钮,文本就会出现在表格中。
在我看来,我必须遵循代码。
<p>Custom Question</p>
<div class="editor-field">
@Html.TextAreaFor(model => model.CustomQuestionText)
@Html.ValidationMessageFor(model => model.CustomQuestionText)
</div>
<div><p><input type="button" value="Lägg till" /></p></div>
</div>
这是我要填写文本的表格:
<table id="CustomTable">
<thead><tr><th>Custom questions</th></tr></thead>
<tbody>
</tbody>
</table>
感谢任何使用 Jquery 的解决方案,在此先感谢。
最佳答案
为您的按钮提供一个 ID,然后使用 JQuery click 函数捕获文本框值并将其附加到表中:
<input type="button" id="btnAppend" value="Lägg till" />
<script>
$("#btnAppend").click(function() {
var textboxVal = $("#CustomQuestionText").val();
$("#CustomTable").append("<tr><td>" + textboxVal + "</td></tr>");
});
</script>
关于javascript - 使用 jquery 将 textarea 中的文本添加到表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9885088/