gpt4 book ai didi

javascript - 从alertify.dialog实现中引用外部html文件

转载 作者:行者123 更新时间:2023-11-28 06:37:43 25 4
gpt4 key购买 nike

我们可以在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 文件中,并在对话框实现中引用该文件。我们有什么选择吗?

最佳答案

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

关于javascript - 从alertify.dialog实现中引用外部html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34124091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com