form 表单提交的问题

<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。

 

 

转载于:https://my.oschina.net/weaver/blog/1785750

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值