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);
不起作用。
嘗試$('。modal-body')。scrollTop(0); – user2585299
這就像一個魅力。謝謝 – user1005310
@ user2585299'$('#div-id')。scrollTop(0);'正在工作,非常感謝:) –