js提交表单

来源:互联网 发布:淘宝活动封面 编辑:程序博客网 时间:2024/05/21 10:25

<script>
    function checkValue(){
        var username = document.form.username.value;
        var password = document.form.password.value;
        if(username == ''){
            alert("用户名不能为空!");
            return ;
        }
        if(password == ''){
            alert("密码不能为空!");
            return ;
        }
        document.form.action = "login.do";
    }
</script>    
    <form name="form" method="post">
        <table>
            <tr>
                <td>用户名:</td>
                <td><input name="username" type="text" value=""/></td>
            </tr>
            <tr>
                <td>密码:</td>    
                <td><input name="password" type="text" value=""/></td>
            </tr>
            <tr>
                <td><input type="submit" value="提交" onclick="checkValue();"/></td>
            </tr>
        </table
    </form>