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页面即可。

  • 相关阅读:
    JS-Date日期内置对象
    JS-string内置对象
    MyBatis的事务处理
    MyBatis的简单操作
    MyBatis第一个项目示例
    CSS-盒子模型
    百分比布局的使用
    使用TabLayout快速实现一个导航栏
    彻底理解android中的内部存储与外部存储
    Eclipse的LogCat总是自动清空怎么办?
  • 原文地址:https://www.cnblogs.com/wangjiayi/p/5485458.html
Copyright © 2011-2022 走看看