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)来阻止表单提交,
  • 相关阅读:
    关于App_Offline.htm的应用实例(及CIM_DataFile的用法)注意Windows下
    Office2007多个文档打开时,开启多个窗口(独立进程)
    Asp.Net环境下web Pages,web Forms 及MVC的优越及缺点
    批量生成表Create SQL 示例 Generate SQL Create Scripts for existing tables with Query
    Different between datetime and timestamp, and its setting
    SqlConnection ,SqlTransaction,SqlCommand的常用法
    ASP.NET下从Server端下载文件到Client端C#
    C#中Remote文件复制简例子
    DOS BAT用法简例子
    改善SQL Procedure性能的几点方法
  • 原文地址:https://www.cnblogs.com/gaocong/p/5749998.html
Copyright © 2011-2022 走看看