我有以下Twitter Bootstrap 3模式,在模态内部有一个表单:
<!-- Button trigger modal --> <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h2 class="modal-title">Add new page</h2> </div> <div class="modal-body"> <form class="form-horizontal add-new-page-form"> <fieldset> <!-- Label --> <div class="form-group"> <label class="col-md-4 control-label" for="labelInput">Label</label> <div class="col-md-5"> <input id="labelInput" name="labelInput" type="text" data-field="label" class="form-control input-md"> <span class="help-block">Page label</span> </div> </div> <!-- Button (Double) --> <div class="form-group"> <label class="col-md-4 control-label" for="closeBtn"></label> <div class="col-md-8"> <button id="closeBtn" name="closeBtn" class="btn btn-default" data-dismiss="modal">Close</button> <input type="submit" id="saveBtn" name="saveBtn" class="btn btn-primary add-page" value="Add"> </div> </div> </fieldset> </form> </div> </div> </div> </div>
我想通过jQuery捕获提交事件:
$("form").on("submit",function () { alert("foo"); return false; });
表单不是通过按Enter键提交的(当文本输入被聚焦时),但是在单击“添加”按钮(即提交按钮)时提交.
我找不到为什么表单没有通过回车提交.模态只是关闭,但不会发出/触发提交事件.
JSFDDLE – 可以复制问题
测试了Chromium版本34.0.1847.116 Ubuntu 14.04光环(260972)和Firefox 31.0.两个浏览器上的问题相同.