Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有AJAX内容的Jquery UI对话框,可以';不对焦_Jquery_Ajax_Jquery Ui Dialog - Fatal编程技术网

带有AJAX内容的Jquery UI对话框,可以';不对焦

带有AJAX内容的Jquery UI对话框,可以';不对焦,jquery,ajax,jquery-ui-dialog,Jquery,Ajax,Jquery Ui Dialog,我将内容加载到jQueryUI对话框并抛出ajax,无法将焦点设置在H1标记上。 不管怎样,我不能将焦点设置为对话框的任何元素,它只是叠加在对话框的最后一个元素上 这是我的密码: $(document).on('click', '.home_story_small_top', function( event ){ event.preventDefault(); var storyId = $(this).attr('storyId'); fu

我将内容加载到jQueryUI对话框并抛出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
元素不能被聚焦。。仅输入元素


尝试设置超时暂停
100
毫秒,然后设置焦点。您可能不需要等待
100
毫秒
1
即可。您可以对其进行测试。

我没有看到任何代码看起来像是试图聚焦某个元素……我删除了它,因为它没有多大帮助。我尝试了$('h1')。focus();和$('#storyId').focus();和其他。。。需要说明的是,H1是通过ajax进行动态添加的。将其添加回去,这样我们就可以看到您想要它的位置是的,我在许多不同的元素(H1、a、按钮…)上尝试过它,但在这种情况下,focus()看起来毫无效果;(我还有一件事要尝试。。如果这不起作用,我需要查看您的代码。您可以制作一个共享程序来轻松共享。检查我答案的更新。@user2781361请将此答案标记为已接受。它有助于回答您的问题,或提供反馈。谢谢