[英]Set focus on textbox in AJAX POPUP Load
In my site, Login window open as POPUP using AJAX call. 在我的站点中,使用AJAX调用以POPUP形式打开“登录”窗口。 Please refer below screen grab: 请参考以下屏幕抓取:
$('#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');
}
});
});
Login window have two input fields UserName and Password. 登录窗口有两个输入字段:用户名和密码。 I need to set focus on UserName field when popup open. 打开弹出窗口时,我需要将重点放在UserName字段上。
Many Thanks, 非常感谢,
Regards, Lalitha 问候,拉利萨
I'm gonna complete my comment here , in my complete answer . 我要在这里完整地回答我的评论。
I see that you use fancybox , so I looked at it and saw that there is an option for doing something after the popup complete . 我看到您使用了fancybox, 所以我看了看它 ,发现弹出窗口完成后,有一个选项可以做一些事情。
so you'r gonna have something like this in you'r code: 因此您的代码中将包含以下内容:
$("#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();
so , the focus is been updated after the popup content display successfully. 因此,焦点将在弹出内容显示成功后更新。
good luck and have fun . 祝好运并玩得开心点 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.