0

Every time I press a button, there is a random chance that a alertify alert window popups. The alertify alert popup is something I use instead of javascript Alert, just to get a nicer design.

Alertify library

And here is a screenshot of the current situation:

enter image description here

I want to assign a event to the OK button. When I use the "inspect element" function in google chrome, I see that this green OK button has an id called "alertify-ok", so I want to assign an event when this button is pressed.

I've tried to add this part to my HTML document in the script part:

$( "#alertify-ok" ).on( "click",function() {alert("finally");});

But nothing happens. The reason why I need this to work, is that the youtube popupmodal should come up right after I've pressed the OK button. I belive the error comes because the alertify window with HTML is from an external library, so how can i do this?

4

2 回答 2

0

您可以将事件放在您知道已经存在的元素(如“body”)上,并指定它仅在单击所需元素时触发:

$(" body").on({
    click: function () {...
    }
}, "#trigger");
于 2014-10-04T21:57:53.173 回答
0

警报和其他警报在创建时采用回调函数,https://github.com/alertifyjs/alertify.js/blob/0.3.12/src/js/alertify.js#L608。您不需要附加另一个事件侦听器,只需给它您希望它执行的功能。下面的例子:

alertify.alert("alerttext", function(e) {
    functionIWantToCall();
});
于 2014-10-04T21:48:28.277 回答