弹出窗口javascript(如何将焦点添加到弹出窗口)

发布于 2025-01-07 21:43:28 字数 1402 浏览 3 评论 0原文

如何在此代码中将焦点添加到弹出窗口,请帮助我。

 <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2025-01-14 21:43:28

我认为你的问题在于你期望这一行为

var id = $(this).attr('href');

你提供 window

的引用(如果它是一个,你的代码几乎是有意义的) div),并且该 div 是一个覆盖层(不是弹出窗口)。

我认为您需要找到创建叠加层的代码,然后您可以“.show() " 和 ".focus()" 位于 div 内的字段之一。

I think your problem is with that you expect this line

var id = $(this).attr('href');

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文