javascript - 如何在 Pnotify 中将焦点设置在按钮上

标签 javascript jquery jquery-plugins modal-dialog pnotify

我在我的项目中使用 pnotify alert jquery。当对话框弹出时,我试图将焦点设置在确定按钮上。这样用户只需按回车键或空格键即可关闭对话框。但无法做到这一点。

This is link of pnotify
我的代码-

 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 回调。检查这个demo .

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

关于javascript - 如何在 Pnotify 中将焦点设置在按钮上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28067554/

相关文章:

JQuery 插件结构。带有选项的方法、方法和选项

jquery - 如何终止/重置正在运行的 jquery 插件?

javascript - 如何在测验中一次显示一个元素

Javascript 用 mousemove 绘制一个 div

javascript - 解析网站并使用 'PHP Simple HTML DOM Parser' 保存特定的 DIV

jQuery DataTables - 通过精确匹配过滤列

jquery - 如何删除 Jquery PrintElement 中的 url 和页脚

javascript - 带 Backbone 的下划线模板中的嵌套循环

javascript - 使用 Jquery 从粘性平滑过渡到不粘性

javascript - 谷歌浏览器在使用 javascript 取消选择时不会刷新选择选项