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>
  • 相关阅读:
    数组和json的相互转换
    cocoapods安装完第三方类库后不生成workspace
    CoreDataManager-OC版-兼容iOS10以前的版本
    CoreDataManager-Swift版-兼容iOS10以前的版本
    画虚线
    YYText-显示富文本
    删除项目中的CocoaPods
    CocoaPods的安装
    CocoaPods常用终端命令及Profile文件简单介绍
    根据字符串生成类---类的类型.self---根据字符串创建控制器对象
  • 原文地址:https://www.cnblogs.com/Lulus/p/7873774.html
Copyright © 2011-2022 走看看