滚动到Bootstrap模式弹出窗口的顶部 [英] Scroll to top of Bootstrap modal popup

查看:92
本文介绍了滚动到Bootstrap模式弹出窗口的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面指示的是我的HTML代码,它是Bootstrap模式弹出窗口.我要尝试做的是,如果用户单击保存"按钮,我正在进行某种验证,并且如果验证失败,则会显示该消息,并应自动向上滚动到模式弹出窗口的顶部.但它没有向上滚动.在下面,我还指出了我来自JS文件的代码.

Below indicated is my HTML code, its a Bootstrap modal popup. What I am trying to do is if user clicks on save button, I am doing some sort of validation and if the validation fails, the message is displayed and should automatically scroll up to the top of the modal popup. but its not scrolling up. Below I have also indicated my code from JS file.

<div id="addD" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addPatientLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="addLabel">Create</h3>
    </div>
    <div class="modal-body">
        <p class="validateTips"></p>
        <table>
            <tr>
                <td class="TemplateLabel">
                    Name:
                </td>
                <td align="left">
                    <input placeholder="name" type="text" name="Name" data-bind="value: NewP.Name" id="SignUpName" class="SignUp text ui-widget-content ui-corner-all" />
                </td>
            </tr>
        </table>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-primary" onclick="SaveD()">Save changes</button>
    </div>
</div>

在我的JS文件中:

function SaveD() {
    debugger;
    var bValid = true;

    bValid = bValid && CheckRequired($('#SignUpName'));
    if (bValid) {
        /*Some func called*/
    }
    else
    {
        $('#addD-content').scrollTop(0);
    }
}

有帮助吗?基本上$('#addD-content').scrollTop(0);无法正常工作.

Any help? Basically $('#addD-content').scrollTop(0); is not working.

推荐答案

$('#addD').animate({ scrollTop: 0 }, 'slow');

这篇关于滚动到Bootstrap模式弹出窗口的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆