开发者

lightbox focus on input, only works after refresh

I have a login box that pops up when you click on the login button, and that lightbox will have a login form loaded into it.

I have tried setting onLoad="document.loginForm.login.focus()" to try and set the focus on the login box when the page loads.

However, this seems to only work, after you refresh the login form in the lightbox, not the parent documents behind it.

I have 开发者_如何学编程tried adding a timeout option to the function as I thought it may be a timing issue, but this does not seem to have worked.

Does anyone have any ideas why it works after a refresh, but not on first load?

Thanks Eds


I think this should help you:

$(document).ready(function(){
    $("iframe").load(function(){
        window.frames[0].document.forms['loginForm'].login.focus();
    });
});

If you have more than one iframe in your page, then give an id to your target iframe and use $("#myIframeId") instead of $("iframe")


Try calling document.loginForm.login.focus() on button click event.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜