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 ...
随机推荐
- 一条简单的 SQL 执行超过 1000ms,纳尼?
阅读本文大概需要 2.8 分钟. MySQL 对我说 “Too young, too naive!" ▌大概过程 在测试环境 Docker 容器中,在跨进程调用服务的时候,A 应用通过 Du ...
- 后台接收参数报错 Required String parameter 'id' is not present
来自:https://blog.csdn.net/qq_15238647/article/details/81539287 关于ajax请求spring后台出现 Required String par ...
- [BUAA软工]beta阶段贡献分
团队成员在Beta阶段的角色和具体贡献: 名字 角色 具体的可衡量的可验证的贡献 zpj 前段+ 前后端对接 博客X1 20+ commits ui 设计与实现 bug fixed: 2 推广:10 ...
- 在HPC的节点上使用jupyter notebook
投递任务,注意资源设置 #!/bin/bash #SBATCH --nodes=1 #SBATCH --ntasks=1 #SBATCH --cpus-per-task=1 #SBATCH --mem ...
- 【深入学习linux】在linux系统下怎么编写c语言程序并运行
1. 首先安装下 gcc : centos yum -y gcc 2. 编写c程序保存hello.c: #include <stdio.h> #include <stdlib.h&g ...
- spring.factories spring.schemas spring.handlers spring自动装配
org.springframework.core.io.support.SpringFactoriesLoader —— public static final String FACTORIES_RE ...
- Sword CRC算法原理
CRC校验原理 CRC校验其根本思想a.发送端和接收端约定一个整数 bb.发送端在原始数据帧后面附加一个数 k ,产生一个新的数据帧c.接收端接收到数据帧后,对接收的数据帧和整数 b 进行位异或操作, ...
- Linux下 nohup后台运行springboot jar 包时,使用指定的 application.yml配置
jar 包启动时指定配置文件 application.yml nohup java -jar -Dserver.port=8080 wx-member-card-0.0.1-SNAPSHOT.war ...
- GO语言 文件操作实例
package main import ( "bufio" "fmt" "io/ioutil" "os" ) func ...
- idea 打开eclipse 项目 编译出现 Error:(1, 1) java: 非法字符: ‘\ufeff’
原因分析: Eclipse可以智能的把UTF-8+BOM文件转为普通的UTF-8文件,IDEA没有这个智能转换. 解决: 1 用IDEA转换,先转换为GBK,再转回UTF-8