zoukankan      html  css  js  c++  java
  • html 的 image button 自动提交 form

    【引】

    http://www.cnblogs.com/focus/archive/2007/12/06/984980.html
     

    今天在项目的代码中看到这么一段:
    <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()"/>

     

  • 相关阅读:
    python-paramiko
    python函数
    pyinstaller打包py程序为exe文件
    centos7安装python3.6.4
    docker资源限制
    docker网络管理
    docker run命令
    dockerfile解析
    爬虫基础巩固
    爬取图虫网 示例网址 https://wangxu.tuchong.com/23892889/
  • 原文地址:https://www.cnblogs.com/xryyforver/p/2055964.html
Copyright © 2011-2022 走看看