focus() doesn't work inside colorbox pop-up

前端 未结 6 1739
遇见更好的自我
遇见更好的自我 2021-02-14 11:43

I tried to use focus for first input field on the form. but it doesn\'t work. When I call attr(\"id\") for that input it worked. When I call focus f

6条回答
  •  逝去的感伤
    2021-02-14 12:19

    You are all misunderstanding the question. When Colorbox opens you can't focus an input field?

    ...unless you add your focus to the Colobox onComplete key e.g.

    $('#mydiv a').colorbox({ onComplete:function(){ $('form input:first').focus(); }});
    

    You could also bind the focus to an event hook:

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

    That should be enough to get started.

提交回复
热议问题