簡體   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