focus()在colorbox弹出窗口内不起作用

Yur*_*rko 10 javascript jquery colorbox

我试图focus在表单上使用第一个输入字段.但它不起作用.当我呼吁attr("id")输入时,它起作用了.当我为相同的输入调用焦点时,我没有看到任何结果.我也尝试使用原生Javascript.有谁知道如何解决这个问题?

HGP*_*GPB 5

你们都误解了这个问题.当Colorbox打开时,您无法聚焦输入字段?

...除非你将焦点添加到Colobox onComplete键,例如

$('#mydiv a').colorbox({ onComplete:function(){ $('form input:first').focus(); }});
Run Code Online (Sandbox Code Playgroud)

您还可以将焦点绑定到事件挂钩:

$('#mydiv a').bind('cbox_complete', function(){
        $('form input:first').focus();
});
Run Code Online (Sandbox Code Playgroud)

这应该足以开始.

  • 谢谢,这真的很有帮助 - 实际上回答了问题的一个关键方面。 (2认同)

diE*_*cho 1

使用

$(document).ready(function() {
       // focus on the first text input field in the first field on the page
        $("input[type='text']:first", document.forms[0]).focus();
    });
Run Code Online (Sandbox Code Playgroud)