一个非常简单的FORM和JS:
$('#gg').submit(function() {
alert('s');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="gg" method="post">
<input name="languageId" type="text">
<input name="languageName" type="text">
</form>
.submit不会以某种方式按输入输入触发。但如果我有一个输入,它确实有效!
答案 0 :(得分:5)
如果向表单添加提交输入,则按ENTER键将提交表单。
$('#gg').submit(function() {
alert('s');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="gg" method="post">
<input name="languageId" type="text"/>
<input name="languageName" type="text"/>
<input type="submit"/>
</form>
答案 1 :(得分:3)
实现此目的的一种方法是手动设置回车键,如下所示:
$('#gg input').keypress(function (e) { // listen to keypress on your input controls
if (e.which == 13) { // if enter key...
$('#gg').submit(); // submit the form
}
});
答案 2 :(得分:0)
实际上,添加
<input type="submit" style="display: none;">
似乎解决了所有问题