Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Pnotify中设置foucs on按钮_Javascript_Jquery_Jquery Plugins_Modal Dialog_Pnotify - Fatal编程技术网

Javascript 如何在Pnotify中设置foucs on按钮

Javascript 如何在Pnotify中设置foucs on按钮,javascript,jquery,jquery-plugins,modal-dialog,pnotify,Javascript,Jquery,Jquery Plugins,Modal Dialog,Pnotify,我正在项目中使用pnotify alert jquery。当对话框弹出时,我试图将焦点设置在ok按钮上。这样用户只需点击回车键或空格键即可关闭对话框。但我们无法做到这一点 我的密码- function AlertAskOk(Heading, Message, type, okclick) { var modal_overlay; info_box = $.pnotify({ title: Heading,

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


我的密码-

 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");
                }
            });

        }
函数AlertAskOk(标题、消息、类型、OK单击){
var模态叠加;
信息框=$.pnotify({
标题:标题,
文本:消息,
类型:类型,
按钮:“ok”,
OK点击:OK点击,
图标:“picon picon对象订单提升”,
延误:20000,
历史:错,
堆栈:false,
//非块:对,
打开前:功能(pnotify){
//$(“btn反向”).focus();
//将此通知放置在屏幕中央。
pnotify.css({
“顶部”:($(window.height()/2)-(pnotify.height()/2),
“左”:($(window.width()/2)-(pnotify.width()/2)
});
//制作一个模式屏幕覆盖。
模态叠加=$(“”{
“类”:“ui小部件覆盖”,
“css”:{
“显示”:“无”,
“位置”:“固定”,
“顶部”:“0”,
“宽度”:“5000px”,
“底部”:“0”,
“右”:“0”,
“左”:“0”,
“游标”:“指针”
}
}).appendTo(“body”).fadeIn(“fast”);
},
//....
打开后:功能(ui){
$(“.btn”,ui.container).focus();
},
//....
关闭前:函数(){
模态叠加淡出(“快速”);
}
});
}

打开回调后使用
。看看这个


如果需要对所有PNotify更改此选项,我将使用下一个解决方案:

PNotify.prototype.options.confirm.buttons[0].addClass = 'btn-pnotify-ok';

PNotify.prototype.modules.confirm.afterOpen = function(notice, options){
    if (options.prompt) {
        this.prompt.focus();
    } else {
        notice.container
            .keyup(({keyCode}) => {
                if (keyCode === 27) {
                    notice.remove();
                }
            })
            .find('.btn-pnotify-ok')
            .focus();
    }
};

new PNotify({...}); 
...
new PNotify({...}); 

PNotify.prototype.options.style='bootstrap3';
PNotify.prototype.options.confirm.buttons[0]。addClass='btn PNotify ok';
PNotify.prototype.modules.confirm.afterOpen=功能(注意,选项){
if(options.prompt){
this.prompt.focus();
}否则{
注意:集装箱
.keyup({keyCode})=>{
如果(键代码===27){
注意。删除();
}
})
.find(“.btn pnotify ok”)
.focus();
}
};
$(“#btn1”)。单击(函数(){
新通知({
标题:“关注开放式#1”,
文本:“按[enter]或[esc]!”,
隐藏:错,
堆栈:{
“模态”:正确,
'dir1':'down',
'dir2':'right',
},
确认:{
确认:对,
},
按钮:{
闭嘴:错,
标签:假
},
});
});
$(“#btn2”)。单击(函数(){
新通知({
标题:“关注公开赛#2”,
文本:“按[enter]或[esc]!”,
隐藏:错,
堆栈:{
“模态”:正确,
'dir1':'down',
'dir2':'right',
},
确认:{
确认:对,
},
按钮:{
闭嘴:错,
标签:假
},
});
});

确认对话框#1

确认对话框#2
@dvirus您的按钮是否具有class
btn
?你可以添加你的html,或者创建一个提琴吗?
PNotify.prototype.options.confirm.buttons[0].addClass = 'btn-pnotify-ok';

PNotify.prototype.modules.confirm.afterOpen = function(notice, options){
    if (options.prompt) {
        this.prompt.focus();
    } else {
        notice.container
            .keyup(({keyCode}) => {
                if (keyCode === 27) {
                    notice.remove();
                }
            })
            .find('.btn-pnotify-ok')
            .focus();
    }
};

new PNotify({...}); 
...
new PNotify({...});