更新以解决如何将 pnotify 附加到标头类
在我重新阅读您的问题后,我假设您可能正在寻找类似此更新示例中的内容。数据属性下方提供了 pnotify 消息的标题和文本。
<div class="header"
data-title="notify 1"
data-text="text 1">Header with autowiring of pnotify</div>
<div class="header"
data-title="better notify 2"
data-text="other text 2">Header 2</div>
要将 pnotify 与标头类连接起来,您可以添加以下代码:
function getNotifiyMessage(that){
var mytitle = $(that).attr("data-title" );
var mytext = $(that).attr("data-text");
return { title: mytitle, text: mytext};
};
$(document).ready(function() {
$(".header").click(
function(){
var notifyMessage = getNotifiyMessage(this);
$.pnotify(notifyMessage);
}
);
});
较早的第一个答案
如果你的意思是这个基于样本的pnotify
<button class="btn btn-default source"
onclick="$.pnotify({ title: 'Regular Notice'
, text: 'i am a note from pnotify'});"
>Regular Notice</button>
您可以通过添加带有激活 pnotify 功能的 onclick 属性来创建 pnotify。请参阅
此示例下面的 data-attribute 提供了 pnotify 消息的标题和文本。
<div class="header"
onclick="$.pnotify({ title: 'Regular Notice', text: 'i am a note from pnotify'});">
<div class="col-md-12"
data-bind="with: activeRoute">go click me to see pnotify</div>
</div>
请注意,上面的事件从内部 div 冒泡到外部 div,然后 pnotify 触发。