javascript 如何在 jquery 对话框中加载 html 页面。?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9486624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to load a html page in a jquery dialogbox.?
提问by Harshil Shah
I have created a dialog box and i want to load a HTML page into it h
我创建了一个对话框,我想将一个 HTML 页面加载到其中 h
回答by Patrick Moore
Assuming your dialog box is #dialog (<div id="dialog"></div>
), this would work:
假设您的对话框是 #dialog ( <div id="dialog"></div>
),这将起作用:
$.get("url/to/yourpage.html", function(data) {
$("#dialog").html( data );
});
回答by Manse
Something like this :
像这样的事情:
var url = "the url";
var dialog = $("#dialog");
if ($("#dialog").length === 0) { // only create if it doesn't exist
dialog = $('<div id="dialog"></div>').appendTo('body');
}
// load remote content
dialog.load(
url, {}, function(responseText, textStatus, XMLHttpRequest) {
dialog.dialog({
// your options
})
}?)
回答by charlietfl
Since you said you've already created the dialog, loading and opening then become as simple as:
既然你说你已经创建了对话框,那么加载和打开就变得如此简单:
$('#dialog').load( url, function(){
$(this).dialog('open');
});