FORM表单中onclick()、submit()与onsubmit()的问题
来源:互联网 发布:抓取数据 编辑:程序博客网 时间:2024/05/01 01:10
最近遇到一次处理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();” 才能取得函数的返回值,否则只是调用函数,返回值未被传递
正确写法:
0 0
- FORM表单中onclick()、onsubmit()与submit()的问题
- FORM表单中onclick()、submit()与onsubmit()的问题
- FORM表单中onclick()、submit()与onsubmit()的问题
- FORM表单中onclick()、submit()与onsubmit()的问题
- FORM表单中onclick()、submit()与onsubmit()的问题
- JS中对于form表单提交时验证form的onsubmit函数与submit类型按钮的onclick函数
- onsubmit阻止form表单提交与onclick的相关操作
- onsubmit阻止form表单提交与onclick的相关操作
- onsubmit阻止form表单提交与onclick的相关操作
- onsubmit阻止form表单提交与onclick的相关操作
- form 表单提交 submit与onsubmit 区别
- form 表单提交中onClick和onsubmit的区别
- form表单的onsubmit和submit
- form的submit与onsubmit的用法
- form表单的onsubmit()问题
- form表单的onsubmit()问题
- form表单的onsubmit()问题
- form表单的onsubmit()问题
- php windows下的定时程序
- [Android实例] 仿微信摇一摇功能实现
- Android getDecorView用途——屏幕截图
- 2016年想读的几本书
- sass 学习总结
- FORM表单中onclick()、submit()与onsubmit()的问题
- shell中各种括号的作用()、(())、[]、[[]]、{}
- android中Handler总结
- Windows图形编程笔记
- SQL 查询表字段信息
- js常用字符串操作方法
- mysql 导入sql文件乱码
- 萌萌哒的
- C#实现老板键功能的代码