溺水墨斗鱼 2021-07-29 17:14 采纳率: 60%
浏览 91
已结题

为什么return false没能阻止页面跳转

1.为什么return false没能阻止页面跳转,只有把return false放进每个if语句中页面才能不跳转
2.password和repwd都是jQuery对象,为什么可以使用==比较,js才用的是==比较,哪里有写过jQuery可以用==比较呢


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>尚硅谷会员注册页面</title>
<link type="text/css" rel="stylesheet" href="../../static/css/style.css" >
    <script type="text/javascript" src="../../static/script/jquery-1.7.2.js"></script>
<style type="text/css">
    .login_form{
        height:420px;
        margin-top: 25px;
    }
    
</style>
    <script type="text/javascript">
        $(function () {

            $("#sub_btn").click(function () {
                var username = $("#username").val();
                var password = $("#password").val();
                var repwd = $("#repwd").val();
                var email = $("#email").val();

                var Exp = /\w{5,12}/;//\w表示任意字母、数字、下划线
                if(!Exp.test(username)){
                    $(".errorMsg").text("用户名不合法");
                }
                if(!Exp.test(password)){
                    $(".errorMsg").text("密码不合法");
                }
                if (password == repwd){
                    $(".errorMsg").text("两次密码输入不一致");
                }


                return false;

            });

        });
    </script>
</head>
<body>
        <div id="login_header">
            <img class="logo_img" alt="" src="../../static/img/logo.gif" >
        </div>
        
            <div class="login_banner">
            
                <div id="l_content">
                    <span class="login_word">注册</span>
                </div>
                
                <div id="content">
                    <div class="login_form">
                        <div class="login_box">
                            <div class="tit">
                                <h1>注册尚硅谷会员</h1>
                                <span class="errorMsg"></span>
                            </div>
                            <div class="form">
                                <form action="regist_success.html">
                                    <label>用户名称:</label>
                                    <input class="itxt" type="text" placeholder="请输入用户名" autocomplete="off" tabindex="1" name="username" id="username" />
                                    <br />
                                    <br />
                                    <label>用户密码:</label>
                                    <input class="itxt" type="password" placeholder="请输入密码" autocomplete="off" tabindex="1" name="password" id="password" />
                                    <br />
                                    <br />
                                    <label>确认密码:</label>
                                    <input class="itxt" type="password" placeholder="确认密码" autocomplete="off" tabindex="1" name="repwd" id="repwd" />
                                    <br />
                                    <br />
                                    <label>电子邮件:</label>
                                    <input class="itxt" type="text" placeholder="请输入邮箱地址" autocomplete="off" tabindex="1" name="email" id="email" />
                                    <br />
                                    <br />
                                    <label>验证码:</label>
                                    <input class="itxt" type="text" style="width: 150px;" id="code"/>
                                    <img alt="" src="../../static/img/code.bmp" style="float: right; margin-right: 40px">                                    
                                    <br />
                                    <br />
                                    <input type="submit" value="注册" id="sub_btn" />
                                    
                                </form>
                            </div>
                            
                        </div>
                    </div>
                </div>
            </div>
        <div id="bottom">
            <span>
                尚硅谷书城.Copyright &copy;2015
            </span>
        </div>
</body>
</html>
  • 写回答

4条回答 默认 最新

  • 崽崽的谷雨 2021-07-30 09:55
    关注

    1.先确定是否确实三个if都没执行
    2.jq就是js封装的。js语法完全一样==当然可以使用。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 2月24日
  • 已采纳回答 2月16日
  • 创建了问题 7月29日

悬赏问题

  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline