JavaScript 代码:
function openBlockEditor(block, nick) {
var blockInfo = $.ajax({
url: "in/GameElement/BlockEditor.php",
type: "GET",
data: 'block=' + block + '&nick=' + nick,
dataType: "html"
});
blockInfo.done(function(msg) {
$("#dialog-modal").html(msg).dialog();
$('.ui-dialog-title').html("Block editor")
});
blockInfo.fail(function(jqXHR, textStatus) {
alert( "Please report this: " + textStatus );
}); }
我正在使用默认的 jquery css 和 js 文件。请告诉我在此代码上添加一些模态对话框参数的正确方法?我正在学习 Ajax 。此代码 100% 有效,但我需要一些示例如何设置对话框窗口动画和大小参数。谢谢。
最佳答案
而不是在没有任何选项的情况下执行 .dialog()
只传递一些,你会在文档中找到很多http://api.jqueryui.com/dialog/ 例如,一些动画和您的标题可以是。
$("#dialog-modal").html(msg).dialog({
title:"Block editor",
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
options只是作为一个对象传递,理解一下,这个是一模一样的
var options = {
title:"Block editor",
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
}
... .modal(options)
为了让它发挥作用,对于你的情况可能是这样的:
function openModal(selector,content,title){
$(selector).dialog({
open:function(){
$(selector).html(content);
},
title:title,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
}
你只需像这样打开对话:
blockInfo.done(function(msg) {
openModal("#dialog-modal",msg,"block content");
});
因此您可以选择内容标题和选择器,您可以传递文档中声明的所有内容
玩得开心!
关于javascript - 如何为此代码添加模态窗口参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20928187/