zoukankan      html  css  js  c++  java
  • Form submit

    方法1:使用form onsubmit标签 return XXX()方法

    <!--onsubmit-->
    <form id="formid" name="myform" method='post' onsubmit="return checkUser();">
        <table border="0">
            <tr>
                <td width="60" height="40" align="right">用户名&nbsp;</td>
                <td><input type="text" value="" class="text2" name="username" id="userid" /></td>
            </tr>
            <tr>
                <td width="60" height="40" align="right">密&nbsp;&nbsp;码&nbsp;</td>
                <td><input type="password" value="" class="text2" name="userpass" id="userpassid" /></td>
            </tr>
            <tr>
                <td width="60" height="40" align="right">&nbsp;</td>
                <td>
                    <div class="c4">
                        <input type="submit" value="登录" class="btn2"/>
                    </div>
                </td>
        </table>
    </form>
    
    <script>
        function checkUser() {
            var result = document.getElementById("userid").value;
            var password = document.getElementById("userpassid").value;
            if (result == "") {
                alert("用户名不能为空");
                return false;
            }
            if (password == "") {
                alert("密码不能为空");
                return false;
            }
        }
        debugger;
        alert('Your data is correct.');
    </script>
    

    方法2:input onclick标签

    <form id="formid" name="myform" method='post'>
        <table border="0">
            <tr>
                <td width="60" height="40" align="right">用户名&nbsp;</td>
                <td><input type="text" value="" class="text2" name="username" id="userid" /></td>
            </tr>
            <tr>
                <td width="60" height="40" align="right">密&nbsp;&nbsp;码&nbsp;</td>
                <td><input type="password" value="" class="text2" name="userpass" id="userpassid" /></td>
            </tr>
            <tr>
                <td width="60" height="40" align="right">&nbsp;</td>
                <td>
                    <div class="c4">
                        <!--onclick-->
                        <input type="submit" value="登录" class="btn2" onclick="checkUser();"/>
                    </div>
                </td>
        </table>
    </form>
  • 相关阅读:
    正则如何匹配div下的所有<li>标签?
    日历
    生成一定数量的不重复随机数
    PHP微信红包的算法实现探讨
    Flask 快速使用 —— (1)
    Django rest framework(8)---- 视图和渲染器
    Django 组件之 ----- content-type
    Django rest framework(7)----分页
    Django rest framework(6)----序列化(2)
    Django rest framework(5)----解析器
  • 原文地址:https://www.cnblogs.com/Lulus/p/7873774.html
Copyright © 2011-2022 走看看