Scroll to top of Bootstrap modal popup

谁说我不能喝 提交于 2020-01-04 14:11:53

问题


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>

In my JS file:

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

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

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


回答1:


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


来源:https://stackoverflow.com/questions/24813966/scroll-to-top-of-bootstrap-modal-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!