如何在Pnotify中的按钮上设置焦点 [英] How to set foucs on button in Pnotify

查看:104
本文介绍了如何在Pnotify中的按钮上设置焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用pnotify警报jquery.我试图在对话框弹出时将焦点设置在确定"按钮上.因此用户只需按Enter或空格键即可关闭对话框.但无法做到这一点.

i am using pnotify alert jquery in my project. i am trying to set focus on ok button when dialog box popup. so that user can simply hit enter or space bar to close the dialog box. but unable to do that.

这是pnotify的链接
我的代码-

This is link of pnotify
My code -

 function AlertAskOk(Heading, Message, type, okclick) {
            var modal_overlay;

            info_box = $.pnotify({
                title: Heading,
                text: Message,
                type: type,
                buttons: 'ok',
                okclick: okclick,

                icon: "picon picon-object-order-raise",
                delay: 20000,
                history: false,
                stack: false,
                // nonblock: true,

                before_open: function (pnotify) {

                    //  $("btn-inverse").focus();
                    // Position this notice in the center of the screen.
                    pnotify.css({
                        "top": ($(window).height() / 2) - (pnotify.height() / 2),
                        "left": ($(window).width() / 2) - (pnotify.width() / 2)
                    });

                    // Make a modal screen overlay.
                    modal_overlay = $("<div />", {
                        "class": "ui-widget-overlay",
                        "css": {
                            "display": "none",
                            "position": "fixed",
                            "top": "0",
                            "width": "5000px",
                            "bottom": "0",
                            "right": "0",
                            "left": "0",
                            "cursor": "pointer"

                        }
                    }).appendTo("body").fadeIn("fast");
                },

                //....

                after_open: function (ui) {
        $(".btn", ui.container).focus();
    },
                //....

                before_close: function () {
                    modal_overlay.fadeOut("fast");
                }
            });

        }

推荐答案

使用after_open 回调.选中此演示.

new PNotify({
   //....
    after_open: function (notify) {
        $(".btn-class", notify.container).focus();
    }
   //....
});

这篇关于如何在Pnotify中的按钮上设置焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆