我们可以在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.');
});
}
关于javascript - 从alertify.dialog实现中引用外部html文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34124091/