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 ...
随机推荐
- 数据结构之LinkList
1.结构: 2.Link代码: public class Link { public int iData; public double dData; public Link next; public ...
- 【Gamma阶段】第一次Scrum Meeting
冰多多团队-Gamma阶段第一次Scrum会议 工作情况 团队成员 已完成任务 待完成任务 卓培锦 推广软件,发放调查问卷 修改可移动button以及button手感反馈优化,编辑器风格切换(夜间模式 ...
- Linux文件系统被占用,磁盘使用量与实际不一致【转】
用lsof检查后才发现原因是,有文件被删除,而进程还活着,因而造成还占用空间的现象 [root@/]# lsof |grep delete 根据lsof列出的进程号,kill这些进程后,空间就释放出来 ...
- c++ Array运用实例
myprint.hpp #include <iostream> #include <string> template <typename T> inline voi ...
- WMS日常运维_WJC
3.25.奥克斯项目Apache的server reached MaxClients setting问题 apachelog报错:[mpm_worker:error] [pid 2486:tid 14 ...
- spring 支持集中 bean scope?
Spring bean 支持 5 种 scope: Singleton - 每个 Spring IoC 容器仅有一个单实例. Prototype - 每次请求都会产生一个新的实例. Request - ...
- (原)x264代码中的码流控制学习
(本文主要是自己的学习笔记,如果有误,请留言,一起讨论和更正.)这里采用x264的代码进行走读的方式,来学习qp在码流控制中过程. 在ABR模式下,当我们设置一个bitrate的平均码率以后,x264 ...
- jzy3D从入门到弃坑_3使用jzy3D0.9画2D散点图--多条线条
jzy3D从入门到弃坑_3 使用jzy3D0.9画2D散点图--多条线条 觉得有用的话,欢迎一起讨论相互学习~Follow Me 主要思路 将多个线条的二维数组读入Scatter对象 存入到同一个画布 ...
- matlab学习笔记11_3高维数组操作 filp, shiftdim, size, permute, ipermute
一起来学matlab-matlab学习笔记11 11_3 高维数组处理和运算 filp, shiftdim, size, permute, ipermute 觉得有用的话,欢迎一起讨论相互学习~Fol ...
- 第一次使用markdown
一级标题 二级标题 三家标题 四级标题 五级标题 六级标题 用两个空格来换行 斜体字 斜体字 加粗字体 加粗字体 斜体加粗字体 斜体加粗字体 无序列表用*或者+或者-: 第一箱 第二项 第三项 第四项 ...