在jquery对话框中加载html页面

Loading html page in jquery dialog

本文关键字:html 页面 加载 jquery 对话框      更新时间:2023-09-26

我试图在jquery对话框中加载html页面,但它不起作用。下面是我的jquery代码。当点击链接时,会触发"openTerms"功能。它打开了对话框,但给我找不到资源的错误。但是,"terms.html"位于项目中,并作为项添加。

 <a id="someclientid" name="someuniqueid" href="javascript:void(0);" onclick="openTerms();">Terms and Conditions</a> 

    <script>
            function openTerms()
    {
        pathArray = location.href.split( '/' );
        protocol = pathArray[0];
        host = pathArray[2];
        url =  pathArray[0] + '//' + pathArray[1]  + '//' + pathArray[2] + '//' + pathArray[3] 
        url = url + "/Orchard.Club" + "/terms.html";
        var page = url;
        alert(url);
        var $dialog = $('<div></div>')
                       .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
                       .dialog({
                           autoOpen: false,
                           modal: true,
                           height: 700,
                           width: 1100,
                           title: "Terms and Conditions",
                           buttons: {                                   
                               Cancel: function () {
                                   $(this).dialog("close");
                               }
                           },
                           close: function () { setFormControls(); },
                           open: function () {
                           }
                       });
        $dialog.dialog('open');
    }
</script>

}

加载内容后,您需要显示对话框

$.get(url, function (data) {
    $("#dialog").html(data).dialog('open');
});

也可以尝试load()方法加载类似的内容

$("#dialog").load(url, function(){
    $(this).dialog('open');
});