[英]Jquery UI Dialog with AJAX content, can't set focus
I load content to jquery UI Dialog threw ajax and can't set focus on H1 tag. 我将内容加载到jquery UI对话框中并抛出了ajax,无法将焦点设置在H1标签上。 And no metter what, i can't set focus to any element of the dialog, it just stack on last element of the dialog. 没什么,我不能将焦点设置在对话框的任何元素上,它只是堆叠在对话框的最后一个元素上。
Here is my code: 这是我的代码:
$(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
});
});
I don't know what your HTML looks like but try waiting for a few milliseconds before focusing. 我不知道您的HTML是什么样的,但是请尝试等待几毫秒再进行聚焦。
open: function() {
setTimeout(function(){$('#storyContent input').focus();},100);
}
Note: I have never tried it but I don't think h1
elements can't be focused.. Only input elements. 注意:我从未尝试过,但我不认为h1
元素不能集中..仅输入元素。
Try a setTimeout to pause for 100
miliseconds and then set the focus. 尝试使用setTimeout暂停100
毫秒,然后设置焦点。 You may not need to wait 100
milliseconds 1
might do it. 您可能不需要等待100
毫秒1
可能会这样做。 You can test it out. 您可以测试一下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.