为什么下面的代码滚动页面?

时间:2015-07-17 06:11:00

标签: javascript jquery html

这是代码。基本上它会在页面中添加一个注册表单:

var currentTime = new Date($.now())
$(panel).addClass('panel-logged-out')

//this -> $('.am-signup').html('<div class="am-info alert-box secondary">Please sign-in to your CLO account.</div><div class="am-popup" style="top: 596px; left: 0px;"> <div class="am-popup-header"> <a href="javascript:" class="am-popup-close-icon am-popup-close"></a> <div class="am-popup-title"></div></div><div class="am-popup-content"><div id="ajax-link" style="display: block;"><div class="am-layout-two-coll"> <div class="am-layout-two-coll-top"></div><div class="am-coll-left"> <div class="am-coll-content"> <div class="am-form am-login-form"> <form name="login" method="post" action="/amember/login"> <fieldset> <legend> Member Login </legend> <div class="_row" id="recaptcha-_row" style="display: none;" data-recaptcha-theme="red"> <div class="element-title" style="display:none;"></div><div class="element am-element-recaptcha" id="recaptcha-element"> </div></div><div class="_row"> <div class="element-title"> <label class="element-title" for="login"> E-Mail Address </label> </div><div class="element"> <input type="text" id="login" name="amember_login" size="15" value="" autofocus="autofocus"> </div></div><div class="_row"> <div class="element-title"> <label class="element-title" for="pass"> Password </label> </div><div class="element"> <input type="password" id="pass" name="amember_pass" size="15"> </div></div><div class="_row"> <div class="element-title"> <label class="element-title" for="remember"> Remember my password? </label> </div><div class="element"> <input type="checkbox" name="remember_login" value="1"> </div></div><div class="_row"> <div class="element"> <input class="button" type="submit" value="Login"> </div></div></fieldset> <input type="hidden" name="login_attempt_id" value="' + currentTime + '"><input type="hidden" name="amember_redirect_url" value="/amember/signup"> </form> </div></div></div><div class="am-coll-right"> <div class="am-coll-content"> <div class="am-form am-sendpass-form"> <form name="sendpass" method="post" action="/amember/sendpass"> <fieldset> <legend> Lost password?</legend> <div class="_row"> <div class="element-title"> <label for="sendpass"> Enter your E-Mail Address </label> </div><div class="element"> <input type="text" name="login" id="sendpass" size="15"> </div></div><div class="_row"> <div class="element"> <input class="button" type="submit" value="Get Password"> </div></div></fieldset> </form> </div></div></div><div class="am-layout-two-coll-bottom"></div></div></div></div></div>')

由于某种原因,它会使页面滚动到表单,如果我将代码注释掉,问题就会消失。可能是什么问题?

这是实时网站:http://www.chineselearnonline.com/amember/signup/fullcourse

修改

以下是评论代码的格式化版本:

不确定它是否与它有关。

<div class="am-info alert-box secondary">Please sign-in to your CLO account.</div>
<div class="am-popup" style="top: 596px; left: 0px;">
    <div class="am-popup-header">
        <a href="javascript:" class="am-popup-close-icon am-popup-close"></a>
        <div class="am-popup-title"></div>
    </div>
    <div class="am-popup-content">
        <div id="ajax-link" style="display: block;">
            <div class="am-layout-two-coll">
                <div class="am-layout-two-coll-top"></div>
                <div class="am-coll-left">
                    <div class="am-coll-content">
                        <div class="am-form am-login-form">
                            <form name="login" method="post" action="/amember/login">
                                <fieldset>
                                    <legend> Member Login </legend>
                                    <div class="_row" id="recaptcha-_row" style="display: none;" data-recaptcha-theme="red">
                                        <div class="element-title" style="display:none;"></div>
                                        <div class="element am-element-recaptcha" id="recaptcha-element"> </div>
                                    </div>
                                    <div class="_row">
                                        <div class="element-title">
                                            <label class="element-title" for="login"> E-Mail Address </label>
                                        </div>
                                        <div class="element">
                                            <input type="text" id="login" name="amember_login" size="15" value="" autofocus="autofocus"> </div>
                                    </div>
                                    <div class="_row">
                                        <div class="element-title">
                                            <label class="element-title" for="pass"> Password </label>
                                        </div>
                                        <div class="element">
                                            <input type="password" id="pass" name="amember_pass" size="15"> </div>
                                    </div>
                                    <div class="_row">
                                        <div class="element-title">
                                            <label class="element-title" for="remember"> Remember my password? </label>
                                        </div>
                                        <div class="element">
                                            <input type="checkbox" name="remember_login" value="1"> </div>
                                    </div>
                                    <div class="_row">
                                        <div class="element">
                                            <input class="button" type="submit" value="Login"> </div>
                                    </div>
                                </fieldset>
                                <input type="hidden" name="login_attempt_id" value="' + currentTime + '">
                                <input type="hidden" name="amember_redirect_url" value="/amember/signup"> </form>
                        </div>
                    </div>
                </div>
                <div class="am-coll-right">
                    <div class="am-coll-content">
                        <div class="am-form am-sendpass-form">
                            <form name="sendpass" method="post" action="/amember/sendpass">
                                <fieldset>
                                    <legend> Lost password?</legend>
                                    <div class="_row">
                                        <div class="element-title">
                                            <label for="sendpass"> Enter your E-Mail Address </label>
                                        </div>
                                        <div class="element">
                                            <input type="text" name="login" id="sendpass" size="15"> </div>
                                    </div>
                                    <div class="_row">
                                        <div class="element">
                                            <input class="button" type="submit" value="Get Password"> </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>
                    </div>
                </div>
                <div class="am-layout-two-coll-bottom"></div>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

自动对焦?

如果您将自动对焦放在用户名输入字段中,浏览器会立即进行自动对焦

<input .... autofocus="autofocus"> 

删除它,它可以工作。