繁体   English   中英

具有AJAX内容的jQuery UI对话框,无法设置焦点

[英]Jquery UI Dialog with AJAX content, can't set focus

我将内容加载到jquery UI对话框中并抛出了ajax,无法将焦点设置在H1标签上。 没什么,我不能将焦点设置在对话框的任何元素上,它只是堆叠在对话框的最后一个元素上。

这是我的代码:

$(document).on('click', '.home_story_small_top', function( event ){

        event.preventDefault();

        var storyId = $(this).attr('storyId');

        function success( html )
        {       
            $("#storyContent").html(html);

            $('#storyContent').dialog({
                modal: true,
                resizable: false,
                height: $(window).height() - 100,
                width: $(window).width() - 400,
                dialogClass: 'noTitleDialog',
                buttons: {
                    Close: function(){
                        $(this).dialog('destroy');
                    }
                },
                open: function() { 
                    $('h1').focus(); 
                }
            });

            $('#newStoryTag' + storyId).hide();
        } 

        $.ajax({  
            url: "/showstory/" + storyId + "/ajax",
            cache: false,  
            success: success 
        });
    });

我不知道您的HTML是什么样的,但是请尝试等待几毫秒再进行聚焦。

open: function() {          
  setTimeout(function(){$('#storyContent input').focus();},100);        
}

注意:我从未尝试过,但我不认为h1元素不能集中..仅输入元素。

尝试使用setTimeout暂停100毫秒,然后设置焦点。 您可能不需要等待100毫秒1可能会这样做。 您可以测试一下。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM