小弟我用js判断form的内容,不符合要求返回false,但是为什么还是提交了

我用js判断form的内容,不符合要求返回false,但是为什么还是提交了?

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>
           ooooo!
        </title>
        <link rel="stylesheet" href="style.css" type="text/css" media="screen"
        />
        <!-- To change the color scheme, change blue.css with green.css, orange.css,
        red.css, purple.css and pink.css -->
        <link rel="stylesheet" href="colors/blue.css" type="text/css" media="screen"
        />
        <script type="text/javascript" src="js/jquery.min.js">
        </script>
        <script type="text/javascript" src="js/jquery.easing.min.js">
        </script>
        <script type="text/javascript" src="js/supersized.3.2.7.js">
        </script>
        <script type="text/javascript" src="js/supersized.shutter.js">
        </script>
        <script type="text/javascript" src="js/jquery.countdown.js">
        </script>
        <script type="text/javascript" src="js/jquery.contact.js">
        </script>
        <script type="text/javascript" src="js/jquery.subscribe.js">
        </script>
        <script type="text/javascript" src="js/jquery.ui.core.min.js">
        </script>
        <script type="text/javascript" src="js/jquery.ui.widget.min.js">
        </script>
        <script type="text/javascript" src="js/jquery.ui.mouse.min.js">
        </script>
        <script type="text/javascript" src="js/jquery.ui.draggable.min.js">
        </script>
        <script type="text/javascript" src="js/custom.js">
        </script>
        <script type="text/javascript">
            var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
            function jump() {
                //清空表单所有数据  
                document.getElementById("firstname").value = "";
document.getElementById("lastname").value = "";
$("#firstnameLabel").text("");
$("#lastnameLabel").text("");
            }

            function check() {
                var txt_xuehao = $.trim($("#xuehao").attr("value"));
var txt_xingming = $.trim($("#xingming").attr("value"));
var txt_xingbie = $.trim($("#xingbie").attr("value"));
var txt_upfile = $.trim($("#upfile").attr("value"));

                var isSuccess = 1;
                var reg = new RegExp("^[0-9]{4}$");

                if (txt_xuehao.length == 0 || txt_xuehao == "输入学号") {
                    alert("请输入学号!");
                    isSuccess = 0;
                } else if (!reg.test(txt_xuehao)) {
                    alert("学号错误,请重新输入!");
                    isSuccess = 0;
                } else if (txt_xingming.length == 0 || txt_xingming == "输入姓名") {
                    alert("请输入姓名!");
                    isSuccess = 0;
                } else if (!isCardName(txt_xingming)) {
                    alert("姓名错误!");
                    isSuccess = 0;
                } else if (txt_upfile.length == 0) {
                    alert("请上传图片!");
                    isSuccess = 0;
                } else if (!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(txt_upfile)) {
                    alert("图片类型必须是gif,jpeg,jpg,png中的一种");
                    isSuccess = 0;
                } else {
                    fileChange(document.getElementById('upfile'));
                }
                if (isSuccess == 0) {
                    return false;
                } else {
                    return true;
                }
                alert("提交成功!");
                return false;
            }

            function isCardName(s) {
                var patrn = /^\s*[\u4e00-\u9fa5]{1,}[\u4e00-\u9fa5.·]{0,15}[\u4e00-\u9fa5]{1,}\s*$/;
                if (!patrn.exec(s)) {
                    return false;
                }
                return true;
            }

            function fileChange(target) {
                var fileSize = 0;
                var rufileResultvalue = '';
                if (isIE && !target.files) {
                    var filePath = target.value;
                    var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
                    var file = fileSystem.GetFile(filePath);
                    fileSize = file.Size;
                } else {
                    fileSize = target.files[0].size;
                }
                var size = fileSize / 1024;
                if (size > 10000) {
                    alert("附件不能大于10M");
                    rufileResultvalue = "图片大小不超过10M,支持gif,jpeg,jpg,png等格式。";
                } else {
                    rufileResultvalue = upfile.value;
                }
                document.getElementById('upfileResult').innerHTML = rufileResultvalue;
            }
        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="container">
                <div id="progress">
                </div>
                <div id="homepage">
                    <h1>
                        <span>
                            亲们
                        </span>
                    </h1>
                    <div id="subscribe">
                        <div id="mesaj"></div>
<form method="post" action="php/subscribe.php" name="subscribeform" id="subscribeform"
                        enctype="multipart/form-data" onsubmit="return check()">
                            <div style="width:300px;height:40px;">
                                <span style="width:100px;text-align:left;">
                                    学号:
                                </span>
                                <input type="text" name="xuehao" id="xuehao" value="输入学号" onclick="javascript:this.value=''"
                                />
                            </div>
                            <div style="width:300px;height:40px;">
                                <span style="width:100px;height:20px;text-align:right;">
                                    姓名:
                                </span>
                                <input type="text" name="xingming" id="xingming" value="输入姓名" onclick="javascript:this.value=''"
                                />
                            </div>
                            <div style="position:absolute;width:110px;height:40px;margin-left:2px;">
                                性别:
                            </div>
                            <div style="width:300px;height:40px;margin-left:8px;">
                                <input type="radio" name="xingbie" value="nan" checked="checked" />
                                <span style="width:100px;height:20px;text-align:right;">
                                    男
                                </span>
                                <input type="radio" style="margin-left:20px" name="xingbie" value="nv"
                                />
                                <span style="width:100px;">
                                    女
                                </span>
                            </div>
                            <div style="position:absolute;width:110px;height:40px;margin-left:2px;">
                                作品图片:
                            </div>
                            <div class="fileInput left">
                                <input type="file" name="upfile" id="upfile" class="upfile" onchange="fileChange(this);"
                                />
                                <span style="position:absolute;margin-top:4px;margin-left:20px
                                ">
                                    上传图片
                                </span>
                                <input class="upFileBtn" type="button" value="上传图片" onclick="document.getElementById('upfile').click()"
                                />
                            </div>
                            <span class="tip left" id="upfileResult">
                                图片大小不超过10M,支持gif,jpeg,jpg,png等格式。
                            </span>
                            <div style="position:relative;width:200px;height:50px;float:left;margin-top:10px;margin-left:55px;">
                                <input type="submit" value="提交" />
                            </div>
                        </form>
                    </div>
                </div>
                <!--end homepage-->
            </div>
            <!--end totoggle-->
        </div>
        <div id="prevthumb">
        </div>
        <div id="nextthumb">
        </div>
        <!--Arrow Navigation-->
        <div id="thumb-tray" class="load-item">
            <div id="thumb-back">
            </div>
            <div id="thumb-forward">
            </div>
        </div>
        <div id="progress-back" class="load-item">
            <div id="progress-bar">
            </div>
        </div>
            <a id="tray-button">
            <img id="tray-arrow" src="images/button-tray-up.png" alt="" />
        </a>
      <script type="text/javascript" src="js/jquery.placeholder.js">
        </script>
    </body>
</html> 

------解决思路----------------------
你的check()真的是返回false吗?
------解决思路----------------------
推荐写法

<form id="info" action="...">
    <!--  
        。。。。
    -->
    <input type="button"  id="submitBtn" value="提交">

</form>
<script>
    var info = document.getElementById( "info" );
    var submitBtn = document.getElementById( "submitBtn" );

    submitBtn.onclick = function () {
        if ( ! check() ) { 
            alert( "校验不通过" );
            return;
        }
        alert( "校验通过,提交表单" );
        info.submit()
    };
</script>

------解决思路----------------------

if (isSuccess == 0) {
                    return false;
                } else {
                    return true;
                }
                alert("提交成功!");
                return false;

前面的isSuccess判断必定return 一个结果 后面的语句都不会执行的……
应该把else{}删掉
------解决思路----------------------
引用:
Quote: 引用:


if (isSuccess == 0) {
                    return false;
                } else {
                    return true;
                }
                alert("提交成功!");
                return false;

前面的isSuccess判断必定return 一个结果 后面的语句都不会执行的……
应该把else{}删掉


我的最后两行其实是没用的。。
如果输入的表单有问题,那么isSuccess应该为0,所以最后一个if就return false。
如果表单没有问题,那么isSuccess是1,那么就执行else,return true。

我觉得应该木有问题啊。但是现在的情况是表单有问题,也能提交。

onsubmit="return check()"这个删掉 
<input type="submit" value="提交" /> 加上onclick事件 先检验check 再提交 类似2L的写法