弹出窗口javascript(如何将焦点添加到弹出窗口)
如何在此代码中将焦点添加到弹出窗口,请帮助我。
<script>
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(10);
$('#mask').fadeTo("fast",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/8-$(id).height()/2);
$(id).css('left', winW/2.5-$(id).width()/2);
//transition effect
$(id).fadeIn(100);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
How to add focus to popup window in this code please help me someone.
<script>
$(document).ready(function() {
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set heigth and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeIn(10);
$('#mask').fadeTo("fast",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(id).css('top', winH/8-$(id).height()/2);
$(id).css('left', winW/2.5-$(id).width()/2);
//transition effect
$(id).fadeIn(100);
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask').hide();
$('.window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});
});
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的问题在于你期望这一行为
你提供
window
或的引用(如果它是一个,你的代码几乎是有意义的) div),并且该 div 是一个覆盖层(不是弹出窗口)。
我认为您需要找到创建叠加层的代码,然后您可以“.show() " 和 ".focus()" 位于 div 内的字段之一。
I think your problem is with that you expect this line
to give you the reference of a
window
or a<div>
(your code would almost make sense if it was a div), and that the div was an overlay (not popup).I think you need to find the code which creates the overlay, and then you can ".show()" and ".focus()" on one of the fields inside the div.