作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的项目中使用 pnotify alert jquery。当对话框弹出时,我试图将焦点设置在确定按钮上。这样用户只需按回车键或空格键即可关闭对话框。但无法做到这一点。
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/
我是一名优秀的程序员,十分优秀!