开发者

jQuery: focus()

I have a fancybox that ajax calls file.php to get the content to show. file.php contains:

<SCRIPT>
jQuery(document).ready(function($) {
$('[name=replyMsg]').focus();
});
</SCRIPT>

but still it wont focus on the element when the box opens.

How can I fix this/any solution?

My fancybox settings looks like this:

    $("a.f开发者_JS百科ancybox_wallConv").each(function(){
       $(this).fancybox({
        titleShow     : false,
        width:    380,
        height:   190,
        autoDimensions: false,
        overlayOpacity: 0.3, 
 showNavArrows: false,
centerOnScroll: true,
        href: "file.php"
      }); 
    });

I am using the href function for the ajax call.

http://fancybox.net/api


You're attempting to call focus() before the fancybox appears. Instead of putting that call in ready(), put it in onComplete().

   $("a.fancybox_wallConv").each(function(){
       $(this).fancybox({
        titleShow     : false,
        width:    380,
        height:   190,
        autoDimensions: false,
        overlayOpacity: 0.3, 
        showNavArrows: false,
        centerOnScroll: true,
        href: "file.php",
        onComplete: function() { $('[name=replyMsg]').focus(); }
      }); 
    });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜