FORM表单 onclick()与onsubmit()
FORM表单中onclick()、submit()与onsubmit()的问题
最近遇到一次处理form数据的过滤,采用了button的onclick事件来检查,发现return false后表单仍然提交了。
于是仔细研究了下onclick、onsubmit、submit集合函数之间的关系和区别
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
onsubmit:You can override this event by returning false in the event handler.Use this capability to validate data on the client side to prevent invalid data from being submitted to the server.If the event handler is called by the onsubmit attribute of the form object,the code must explicitly request the return value using the return function,and the event handler must provide an explicit return value for each possible code path in the event handler function.The submit method does not invoke the onsubmit event handler.submit:The submit method does not invoke the onsubmit event handler.Call the onsubmit event handler directly.When using Microsoft? Internet Explorer 5.5 and later,you can call the fireEvent method with a value of onsubmit in the sEvent parameter. |
首先生成一个form
|
1
2
3
4
|
<form action="#" method="POST" name="A" onsubmit="return X();"><input type="text" value="" /><input onclick="Y()" type="submit" value="提交" /></form> |
自己写X()、Y()函数,我们会发现,这几个函数的执行顺序
1) onclick: Y();
2) onsubmit: X();
3) submit();
也就是说
只要 onclick 未 return false 那么就继续执行 onsubmit
只要 onsubmit 未return false 那么表单就被提交出去了
另外一点写法上注意一定要 “return X();” 才能取得函数的返回值,否则只是调用函数,返回值未被传递
正确写法:
<input type=submit onclick=”return X();”>
//X() 返回false后,form的submit会被终止
错误写法:
<input type=submit onclick=”X()”>
//X() 返回false后未传递给onclick事件,form的submit会继续
FORM表单 onclick()与onsubmit()的更多相关文章
- JS中 submit提交与Form表单里的onsubmit的调用问题?
最近在开发中遇到了表单提交前验证的问题,用一个普通的button按钮代替submit按钮,在提交前触发这个button的onclick事件,在其事件中触发form的submit事件.问题出现了: &l ...
- form 表单onclick事件 禁止表单form提交
最近遇到一次处理form数据的过滤,采用了button的onclick事件来检查,发现return false后表单仍然提交了. 于是仔细研究了下onclick.onsubmit.submit集合函数 ...
- Jquery实现form表单提交后局部刷新页面的多种方法
最近做一个小项目,刚好需要用到搜索功能,实现搜索框内输入数据然后按回车或者点击“提交”,然后给后台数据库处理并返回数据给前端,在前端局部更新数据. 但是遇到了一个小问题,就是form表单下任意输入框输 ...
- 提交Form表单,submit之前做js判断处理
效果: 在点击提交按钮时,首先进行js判断, 如果不符合条件,则alert出提示信息,并return false. 主要点就在于给form表单添加一个onsubmit事件. 在onsubmit事件中定 ...
- form表单验证-Javascript
Form表单验证: js基础考试内容,form表单验证,正则表达式,blur事件,自动获取数组,以及css布局样式,动态清除等.完整代码如下: <!DOCTYPE html PUBLIC &qu ...
- form表单的字符串进行utf-8编码
<form>表单有assept-charset属性.该属性规定字符的编码方式,默认是"unknown",与文档的字符集相同. 该属性除了Internet explore ...
- react引用antd的form表单
引用form是第三方插件ant插件,官网网址:https://ant.design/.用到的antd的版本是@2.0.1.form(https://ant.design/components/form ...
- Html:form表单
1:onsubmit 事件:会在表单中的确认按钮被点击时发生. <form action="" method="post" name="form ...
- Form表单的操作
form对象 <form name=“form1” action=“login.php” method=“post”></form> form对象的属性 name:表单名称 m ...
随机推荐
- DELPHI开始支持LINUX DOCKER
DELPHI开始支持LINUX DOCKER 本方翻译自Marco Cantu的文章. 在过去的几年中,将服务器端解决方案(实际上是任何类型的应用程序)部署到轻量级容器而不是物理机器或虚拟机已经变得越 ...
- 如何查看android studio sdk路径配置
file–>Other Settings–>Default Project Structure
- mac opencv 提示摄像头权限问题
通常在iOS开发下,我们的app需要在Info.plist文件中配置所需要的各种限制:如摄像头权限: 本次我们在mac下创建了一个command line 程序,并且设定是c++开发,并配置了open ...
- dubbo连接过程
场景1 启动时 dubbo服务提供端在Zookeeper上注册的节点目录:假设接口名称是:com.bob.dubbo.service.CityDubboService dubbo服务提供端连接到注册中 ...
- mybatis如何接受map类型的参数
Mybatis传入参数类型为Map mybatis更新sql语句: ? 1 2 3 4 5 6 7 8 9 <update id="publishT00_notice" ...
- Linux shell字符串操作
#!/bin/bash #镜像名 image="asr-server" #镜像版本 ver="5.2.1" #容器名 dname="asr" ...
- 【GMT43智能液晶模块】例程十八:LAN_HTTP实验——网页服务器
源代码下载链接: 链接:https://pan.baidu.com/s/1sr4a7TBPyvs18jTfCfVj8Q 提取码:jwfv 复制这段内容后打开百度网盘手机App,操作更方便哦 GMT43 ...
- Cisco ASA 5505配置详解(v8.3之前版本)
在配ASA 5505时用到的命令 2009-11-22 22:49 nat-control命令 在6.3的时候只要是穿越防火墙都需要创建转换项,比如:nat:static等等,没有转换项是不能穿越防火 ...
- Hive学习笔记——parse
Hive是如何解析SQL的呢,首先拿hive的建表语句来举例,比如下面的建表语句 create table test(id int,name string)row format delimited f ...
- iOS - 获取系统时间年月日,阳历(公历)日期转农历的方法
//获取当前时间 NSDate *now = [NSDate date]; NSLog(@" now date is: %@ ",now); NSCalendar *calenda ...