我以为这会很简单。只是
...
onShow:function(dialog){
dialog.data.find("input#myInput").focus();
}
...
但似乎不起作用。
与SimpleModal的focus()函数有冲突吗?
我注意到,如果我在 onShow 函数中放置一个alert(),它会在模态可见之前弹出。有没有办法在显示模式后调用函数(即 focus()),但无需用户输入(无需用户触发某种事件)?
此外,当我尝试使用 simplemodal 时
focus:true
与dialog.data =
'<div class="myModal login">'+
'<div class="modalTitle">Title</div>'+
'<div class="modalContent">'+
'<label for="username">Login: </label>'+
'<input id="username" />'+
'<br />'+
'<label for="password">Pass: </label>'+
'<input id="password" type="password" />'+
'<br />'+
'<div class="confirmButton no simplemodal-close">Cancel</div>'+
'<div class="confirmButton yes">Login</div>'+
'</div>'+
'</div>'
焦点是包装器(至少我是这么认为),用户必须按 Tab 才能到达第一个输入元素。
任何帮助都会很棒,
格雷格。
最佳答案
试试这个:
onShow:function(dialog){
setTimeout(function(){
dialog.data.find("input#myInput").focus();
},50);
}
希望这有帮助。干杯
关于jquery - Simplemodal - 如何在 onShow 函数中将焦点设置在元素上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5921351/