如何向 jquery 插件函数添加回调

how to add a callback to jquery plugin function

我正在使用 jquery 插件来发出以下警报:-

 function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,                   
                icon: icon,                   
                draggable: true
            });
        }

我想给上面的函数添加一个回调,这样当用户点击警告框的 "ok" 按钮时,页面就会重定向到给定的路径。

  $(window.location.replace(newWindow));

我试过下面的代码,但它没有重定向。

   function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,                
                icon: icon,                  
                draggable: true
            }, function () {
                $(window.location.replace(newWindow));
            }
            );
        }

我猜你正在使用 this plugin

阅读回调文档部分后,我认为这段代码应该适合您:

  function alertWithNewWindow(title, content, icon, newWindow) {
            $.alert.open({
                title: title,
                content: content,
                align: 'center',
                icon: icon,
                maxHeight: 160,
                draggable: true,
                callback: function(){
                       $(window.location.replace(newWindow));
                   } 
            );
        }