[英]how to set focus on jquery confirm dialog
我有一個簡單的 jquery 確認對話框,並希望將焦點放在對話框本身而不是任何其他元素上。 下面的代碼是我所做的重點:
function showAlert() {
$("#dialog-confirm").dialog({
title: 'Main Information',
resizable: false,
height:140,
modal: true,
closeOnEscape:true,
buttons: {
"Yes": function() {
document.getElementById('form1:newProfile' ).value="true";
if(disableSaveFlag) return false; else disableEnableSaveBtn('true');
$( this ).dialog( "close" );
},
"No": function() {
document.getElementById('form1:newProfile' ).value="false";
if(disableSaveFlag) return false; else disableEnableSaveBtn('true');
$( this ).dialog( "close" );
}
}
});
$("#dialog-confirm").focus(); // this line sets focus on div element with given id
}
<div id="dialog-confirm" style="display:none">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
Do you want to create a new profile ?
</p>
</div>
只需按Tab<\/kbd> ,它將聚焦對話框的第一個元素。
"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.