简体   繁体   English

如何在jQuery中的noty中添加事件onClick?

[英]How to add event onClick in noty for notifications in jQuery?

I just want to go to a URL in my noty object is clicked (not when it's closed, only when the user clicks the notification). 我只想转到单击我的noty对象中的URL(不是在关闭时,仅当用户单击通知时)。 I tried this: 我尝试了这个:

var n = noty({
    text: 'Nuevo Comentario: <br>' + data.contenido + ' de ' + data.usuario,
    layout: 'bottomRight',
    type: 'information',
    timeout: 3500,
    callback: { onClose: function() { /* Go to the URL i want to go */ }},
    animation: {
        open: {height: 'toggle'}, // jQuery animate function property object
        close: {height: 'toggle'}, // jQuery animate function property object
        easing: 'swing', // easing
        speed: 500 // opening & closing animation speed
    }
});

but the event is triggered even when it closes by itself. 但是即使事件本身关闭,也会触发该事件。 How can I check for when the user clicks on the notification? 我如何检查用户单击通知的时间?

you can try this hack and it work fine 您可以尝试这种技巧,并且效果很好

           new Noty({
                layout: 'bottomRight',
                text: '<h6 onclick="clickOfDT()">_your text</h6>',
                type: 'warning',
                closeWith: ['button']
            }).show();

            clickOfDT=()=>{
                // HERE YOU GOT THE EVENT
            };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM