zoukankan      html  css  js  c++  java
  • submit和button提交表单的区别

    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>submit</title>
    <script type="text/javascript">
    function checkForm(){
        if(document.form1.userName.value.length==0){
            alert("请输入用户名!");
            return false;
        }
        return true; 
        document.form1.submit(); 
    }
    </script>
    </head>
    <body>
    <form name="form1"  method="post" action="ygdacx.html" onsubmit="return checkForm()">
        <input type="text" name="userName" size="10" />
        <input type="submit" value="提 交" />
    </form>
    </body>
    </html>

    当类型为submit的input提交form表单时,配合onsubmit写事件。

    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
    <title>button</title>
    <script type="text/javascript">
    function checkForm(){
        if(document.form1.userName.value.length==0){
            alert("请输入用户名!");
            return false;
        }
        document.form1.action="/email.php"
        document.form1.submit();
    }
    </script>
    </head>
    <body>
    <form name="form1" method="post">
    <button type="button" value="提 交"  onclick="checkForm()"></button>
    </form>
    </body>

    使用button的话是先走一个onclick事件,在事件末端指向要跳转的php页面即可。

  • 相关阅读:
    来自师兄的Django2.0笔记摘录
    2019-03-24 周日
    关于Djanggo的环境变量
    接口文档模板(Markdown)
    Nginx配置
    虚拟机和宿主机通信
    node+mongodb+win7
    【进击后端】linux安装最新版nodejs
    【进击后端】ubuntu 快速安装node mongodb express
    【进击后端】mongodb入门
  • 原文地址:https://www.cnblogs.com/wangjiayi/p/5485458.html
Copyright © 2011-2022 走看看