惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Security Archives - TechRepublic
Security Archives - TechRepublic
V
Vulnerabilities – Threatpost
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Proofpoint News Feed
G
GRAHAM CLULEY
P
Privacy International News Feed
The Hacker News
The Hacker News
Forbes - Security
Forbes - Security
U
Unit 42
N
News and Events Feed by Topic
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Cisco Blogs
A
About on SuperTechFans
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
I
Intezer
Spread Privacy
Spread Privacy
The Last Watchdog
The Last Watchdog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
F
Full Disclosure
S
Secure Thoughts
M
MIT News - Artificial intelligence
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
W
WeLiveSecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Project Zero
Project Zero
Recorded Future
Recorded Future
Cyberwarzone
Cyberwarzone
S
Security Affairs
AWS News Blog
AWS News Blog
H
Help Net Security
The GitHub Blog
The GitHub Blog
Hacker News: Ask HN
Hacker News: Ask HN
Vercel News
Vercel News
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Register - Security
The Register - Security
S
Schneier on Security
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
L
LINUX DO - 最新话题
T
Tor Project blog
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog

博客园 - focus

IE浏览器自定义地址协议 -- 通过B/S程序中打开C/S程序 Html编辑器 -- TinyMCE HTML编辑器 -- HtmlArea 用 BindingSource 绑定窗体中控件不失去焦点无法更新数据源的问题 - focus asp.net 服务器控件防止重复提交表单 - focus - 博客园 html 元素的 onpropertychange 事件 c# 操作 Excel : 给单元格增加下拉选项值 动态创建大量 html dom 元素时提升性能 - focus 很黄的日期格式化。。。 - focus - 博客园 Asp.net 导出 .html,.txt 等格式的文件 ActiveReports 打印条码无法设置纸张大小? ActiveReports 代码控制报表连续打印 《JavaScript高级程序设计》读书笔记之一:几个与原始类型等价的引用类型的常用方法和属性 js:delete 操作符 js:for...in 语句(JavaScript For...In Statement) js:字符串类型快速转化成数字类型和数字类型快速转化为字符串类型 Internet Explorer Developer Toolbar IE 最大化和最小化 js trim
html 的 image button 自动提交 form
focus · 2007-12-06 · via 博客园 - focus

Posted on 2007-12-06 11:35  focus  阅读(3636)  评论()    收藏  举报

今天在项目的代码中看到这么一段:
<HTML>
<BODY>
<FORM name="frmData" onsubmit="Login()">
<INPUT type="image" src="submit.gif" name="imgSubmit" value="" />
</FORM>
</BODY>
<script>
 function Login()
 {
  alert('hello');
 }
</script>
</HTML>
奇怪了,这个登陆按钮没写任何代码触发 form 的提交,但是我们的程序又是怎样正确 work 的?
我想是不是在另外的地方用 js 给这个按钮绑定了 onclick 事件?
于是我把代码拷下来,生成了上面的简化版.
在测试中点击图片后,成功弹出 hello.
查阅资料发现,image button 可以自动触发 form 的 onsubmit 事件.
另外通过用 button 测试,还发现一个现象:
<input type="button" name="btnSubmit" value="submit" onclick="frmData.submit()"/>
这样 form 是提交了,但是不会进入 Login 方法.
相关资料解释:
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.
要这样才能调用到 Login 方法:
<input type="button" name="btnSubmit" value="submit" onclick="frmData.fireEvent('onsubmit')"/>
或者
<input type="button" name="btnSubmit" value="submit" onclick="frmData.onsubmit()"/>