FORM表单中onclick()、submit()与onsubmit()的问题
最近遇到一次处理form数据的过滤,采用了button的onclick事件来检查,发现return false后表单仍然提交了。
于是仔细研究了下onclick、onsubmit、submit集合函数之间的关系和区别
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
<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()、submit()与onsubmit()的问题的更多相关文章
- form表单中的submit点击时阻止提交
在form 中增加onsubmit="return false;"属性.
- FORM表单 onclick()与onsubmit()
FORM表单中onclick().submit()与onsubmit()的问题 最近遇到一次处理form数据的过滤,采用了button的onclick事件来检查,发现return false后表单仍然 ...
- jsp中的form表单中的 id和name有什么区别了
<form action="./system/WebServer_webServerLogin" method="post" id="login ...
- form表单中只有一个input时,按回车键后表单自动提交(form表单的一个小坑)
form中只有一个input按回车键表单会自动提交 在一个form表单中,若只有一个input,按回车键表单会自动提交,但是当表单中存在多个input时,按回车键不会执行任何操作,这是form表单的一 ...
- Form表单中的action路径问题,form表单action路径《jsp--->Servlet路劲问题》这个和上一个《jsp--->Servlet》文章有关
Form表单中的action路径问题,form表单action路径 热度5 评论 50 www.BkJia.Com 网友分享于: 2014-08-14 08:08:01 浏览数44525次 ...
- Form表单中method为get和post的区别
序,form表单中的方法分为get和post,但你都知道他们之间的区别吗? Form表单中method为get和post的区别: 例子如下,有个Form表单. <form action=&quo ...
- Form表单中的action路径问题
今天刚接触web,在用jsp和servlet做一个简单的登陆的时候在Form表单action属性和method属性的一些问题: 我遇到的是Form表单提交到servelet处理时遇到的问题: (1 ...
- form表单中的input有哪些类型
form表单中的input有哪些类型 1.button <input type="button"/> 2.checkbox <input type="c ...
- form表单中button按钮返回上一页解决办法
解决Form中button按钮不好用的问题解决办法. 方法一: 1.在Form表单标签中国增加一个属性,如下图,红框处 2.返回按钮样式 3.onclick方法需要跳转的页面,遮挡处为需要返回的页面 ...
随机推荐
- Python运维开发基础02-语法基础【转】
上节作业回顾(讲解+温习60分钟) #!/bin/bash #user login User="yunjisuan" Passwd="666666" User2 ...
- C#操作剪贴板实现复制粘贴
//粘贴 private void tsbPaste_Click(object sender, EventArgs e) { IDataObject iData = Clipboard.GetData ...
- Ubuntu16下apache2安装ssl阿里云证书
1.用下面的命令确保ssl模块已经加载进apache: a2enmod ssl 如果你看到了“Module ssl already enabled”这样的信息就说明你成功了,如果你看到了“Enabli ...
- Control算法相关
Control算法相关 添加新的control算法官方指导教程. 创建一个控制器: 在文件control_config中添加新控制器的配置信息: 注册新控制器. 如何添加新的CAN卡. Apollo中 ...
- 012_k8s专题系列一之进入容器日常op
一.下面列出如何进入正在运行的k8s容器 <1> kubectl get pods #查看所有正在运行的pod NAME READY STATUS RESTARTS AGE nginx-5 ...
- selenium——获取元素的尺寸、文本信息、元素的属性、元素是否可见
[is_disabled 可以用来检查元素是否存在]
- linux shell中 if else以及大于、小于、等于逻辑表达式
在linux shell编程中,大多数情况下,可以使用测试命令来对条件进行测试,这里简单的介绍下,方便需要的朋友 比如比较字符串.判断文件是否存在及是否可读等,通常用"[]"来表示 ...
- 【原创】大数据基础之Hive(4)hive元数据库核心表结构
1 dbs +-------+-----------------------+----------------------------------------------+------------+- ...
- 如何保障Web应用安全性
通过加密算法对关键数据进行加密 通过过滤器防御跨站脚本攻击XSS.跨域请求伪造CRSF和SQL注入 通过安全框架( Shiro.Spring Security )进行认证和授权 设置IP黑白名单来进行 ...
- Python-计算机硬件基础
预习计算机硬件基础1,CPU/内存.硬盘2,存储器 什么是编程语言什么是编程编程的目的运行程序的三大核心硬件重要:运行程序,硬件的工作过程 ------------------------------ ...