2014-07-17 137 views
2

下面显示的是我的HTML代码,它是一个Bootstrap模式弹出窗口。我想要做的是如果用户点击保存按钮,我正在进行某种验证,如果验证失败,则会显示消息并自动滚动到模态弹出窗口的顶部。但它不滚动。下面我还从JS文件中指出了我的代码。滚动到Bootstrap模态弹出窗口顶部

<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);不起作用。

+0

尝试$('。modal-body')。scrollTop(0); – user2585299

+0

这就像一个魅力。谢谢 – user1005310

+0

@ user2585299'$('#div-id')。scrollTop(0);'正在工作,非常感谢:) –

回答

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