我正在使用像这样的引导输入标签
myPage.html
<form th:object="${field}" name="modal" method="post" th:action="@{/ajouterFieldEcran}">
...
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control col-sm-12" value=""
data-role="tagsinput" id="tags">
</div>
</div>
...
我从这篇文章 Bootstrap tags input not displaying the tags 中得到了这个例子
问题是当我输入值并按 Enter 键将其提交到提交的表单中时。
最佳答案
您可以像这样禁用输入标签中的回车键
$(function() {
$("input").keydown(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});
});
将其放入脚本标记中
从输入类中删除 col-sm-12
,您不需要它。
另请注意,您不能在文本框中使用 Enter 键换行(输入类型='text' 按设计为单行),对于多行文本,您需要使用 textarea
关于javascript - 按 Enter 键,提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52126379/