zoukankan      html  css  js  c++  java
  • js阻止表单提交

    <!DOCTYPE html>
    <html>
    <head>
        <title>Simple Login Form</title>
        <meta charset="UTF-8" />
        <meta name="Designer" content="PremiumPixels.com">
        <meta name="Author" content="$hekh@r d-Ziner, CSSJUNTION.com">
        <link rel="stylesheet" type="text/css" href="css/reset.css">
        <link rel="stylesheet" type="text/css" href="css/structure.css">

        <link href="../Scripts/easyui/themes/default/easyui.css" rel="stylesheet" />
        <link href="../Scripts/easyui/themes/icon.css" rel="stylesheet" />
        <link href="../Scripts/easyui/demo/demo.css" rel="stylesheet" />
    </head>

    <body>
        <form id="login_form" class="box login">
            <fieldset class="boxBody">
                <label>用户名</label>
                <input id="userId" type="text" tabindex="1" placeholder="" required>
                <label><a href="#" class="rLink" tabindex="5"></a>密码</label>
                <input id="userPwd" type="password" tabindex="2" required>
            </fieldset>
            <footer>
                <input  type="submit" class="btnLogin" value="登 录" tabindex="4">
            </footer>
        </form>
        <footer id="main">
            <a href="http://wwww.cssjunction.com">新烽光电股份有限公司</a> | <a href="http://www.premiumpixels.com">制作 by 软件部</a>
        </footer>
    </body>
    </html>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="../Scripts/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script>
        document.getElementById("login_form").onsubmit = function () {
            requiredCheck();
            return false;
        };
        function requiredCheck() {
            var userModel = {
                userId: $.trim($("#userId").val()),
                userPwd: $.trim($("#userPwd").val())
            };
            for (var i in userModel) {
                if (userModel.hasOwnProperty(i)) {
                    if (userModel[i] == "") {
                        $.messager.alert('提示', '用户名或密码不能为空', "error");
                        return false;
                    }
                }
            }
            $.post("/Login/LoginCheck.ashx", userModel, function (msg) {
                if (msg.code == 0) {
                    $.messager.alert('提示', msg.result, "error");
                } else {
                    window.location.href = "/index.aspx";
                }
            });
          
        }
    </script>





    注意: 注册form表单的onsubmit事件,return false(在事件处理函数(onsubmit)里面return false)来阻止表单提交,
  • 相关阅读:
    ios 关闭自动修正输入内容
    Tarjan+缩点【强连通分量】【模板】
    初识Tarjan算法
    【尺取法】【转】
    【先加后减拼凑思想】【合成数问题】
    强连通分量【k 算法、t 算法】
    大数【加减乘除】
    洛谷博客地址【置顶!】
    差分约束+spfa【模板】
    【poj3169】【差分约束+spfa】
  • 原文地址:https://www.cnblogs.com/gaocong/p/5749998.html
Copyright © 2011-2022 走看看