1

我们可以在 alertify.dialog() 实现中引用一个外部 HTML 文件吗?目前正在使用下面的代码,它采用 html 代码来构建我的对话框。

alertify.myAlert || alertify.dialog('myAlert',function factory(){
            return {
                main:function(content){
                    this.setContent(content); 
                },
                setup:function(){
                    return {
                        options:{
                            modal:false,
                            basic:true,
                            maximizable:false,
                            resizable:false,
                            padding:false
                        }
                    };
                    },
                    build:function() {                              
                        this.elements.content.innerHTML = "**<html>MY HTML CODE</html>**";
                    },
                     hooks: {
                       onshow: function() {
                         this.elements.dialog.style.height = '50%';
                         this.elements.dialog.style.width = '15%';
                       }
                     }
                };
        });

在这里有所有的 html 代码看起来很脏。我想把它放在一个单独的 .html 文件中,并在对话框实现中引用它。我们有什么选择吗?

4

1 回答 1

0

AlertifyJS中没有内置这样的功能,但您可以使用 jQuery 创建自己的包装器:

// myAlert dialog 
alertify.myAlert || alertify.dialog('myAlert', function factory() {
  return {
    main: function(content) {
      this.setContent(content);
    },
    setup: function() {
      return {
        options: {
          modal: false,
          basic: true,
          maximizable: false,
          resizable: false,
          padding: false
        }
      };
    }
  };
});

//custom wrapper to load external contents
alertify.ajaxAlert = function(url) {
  $.ajax({
    url: url,
  }).success(function(data) {
    alertify.myAlert(data);
  }).error(function() {
    alertify.error('Errro loading external file.');
  });
}

示例 http://plnkr.co/edit/SuFXMRthGpMKKXoG7Yv2?p=preview

于 2015-12-07T10:19:40.850 回答