我正在使用像这样的bootstrap输入标签
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键在输入中提交它时提交的表单。
您可以在输入标签中禁用Enter键,如下所示
$(function() {
$("input").keydown(function(event) {
if (event.keyCode == 13) {
event.preventDefault();
}
});
});
把它放在你的脚本标签里面
从输入类中删除col-sm-12
,你不需要它。
另请注意,您不能在新行的文本框中使用回车键(输入类型='文本'是单行设计),对于需要使用textarea
的多行文本