在我的网站中,使用AJAX调用将登录窗口打开为POPUP。 请参考下面的屏幕抓取:
$('#hrefLogin').click(function () {
var url = $('#divLogin').data('request-path');
$.ajax({
url: url,
type: 'GET',
success: function (data) {
////Render the partial view HTML returned by the action method
$("#divLogin").html(data);
$.fancybox({
href: "#divLogin",
'maxWidth': 420, // set the width
'minHeight': 400,
'maxHeight': 400,
'height':'auto',
'autoSize': false
});
$.fancybox.update();
////Reparse html data to enable MVC data annotation work.
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('form');
}
});
});
登录窗口有两个输入字段UserName和Password。 弹出窗口打开时,我需要将注意力设置在UserName字段上。
非常感谢,
此致 拉莉莎
答案 0 :(得分:0)
我将在完整的答案中完成我的评论。
我看到你使用了fancybox,so I looked at it并看到弹出窗口完成后有一个选项可以做。
所以你会在你的代码中找到类似的东西:
$("#divLogin").html(data);
$.fancybox({
href: "#divLogin",
'maxWidth': 420, // set the width
'minHeight': 400,
'maxHeight': 400,
'height':'auto',
'autoSize': false,
onComplete : function(){
$(".username").focus();
};
});
$.fancybox.update();
因此,在弹出内容成功显示后,焦点已更新。
祝你好运,玩得开心。