在输入键上,提交表单

时间:2018-09-01 08:29:20

标签: javascript html bootstrap-4 bootstrap-modal

我正在使用像这样的引导输入标签

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以在输入的表单中提交时将其提交。

1 个答案:

答案 0 :(得分:2)

您可以在输入标签中禁用Enter键

$(function() {
 $("input").keydown(function(event) {
    if (event.keyCode == 13) {
        event.preventDefault();
    }
 });
});

将其放入您的脚本标签中

从输入类中删除col-sm-12,您不需要。

还请注意,您不能在文本框中使用Enter键来换行(输入类型=“文本”在设计上是单行),对于多行文本,则需要使用textarea

相关问题