<div class="" id="">
<form class="" enctype="multipart/form-data" method="post" action={{actionUrl}} name="viewForm">
<div class="">
<label class="">View Name:</label>
<div class="">
<input type="text" class="" ng-model="viewName" required name="viewName" ng-keyup="onKeyPress($event)" autofocus="autofocus">
</div>
</div>
</form>
</div>
今天帮同事看个问题,大致就是一个简单的监听enter键按下之后,发个post请求回调里刷新一下数据,但是貌似每次都是整个页面刷新。原因是因为她copy的代码里多了这个form标签。
https://api.jquery.com/submit/
参考Jquery文档中的一段说明(黄色背景色)
Depending on the browser, the Enter key may only cause a form submission if the form has exactly one text field, or only when there is a submit button present. The interface should not rely on a particular behavior for this key unless the issue is forced by observing the keypress event for presses of the Enter key.
所以很多时候不要copy paste代码。就算硬要这么搞也要保证自己看懂这些code。