jquery对话框.html()问题

Ski*_*les 4 html jquery dialog external

我正在使用jquery对话框,并希望使用位于同一服务器上的外部html文件设置.html值.我不确定的是如何实现这一目标.

var $tos_dlg = $('<div></div>')
  .html($(this).load('/includes/tos.html'))
  .dialog({
    autoOpen: false,
    title: 'Policies &amp; Terms of Service',
    width: 600,
    height: 400,
    modal: true
});
Run Code Online (Sandbox Code Playgroud)

上面调用.html()的部分是我想要注入外部文件内容的地方.我认为.load函数会以某种方式工作,但不确定这是否是正确的方法,如果是这样,究竟如何实现它.有人可以帮忙吗?

谢谢

gil*_*ly3 9

呼叫.load()$tos_dlg直接:

var $tos_dlg = $('<div></div>')
    .load('/includes/tos.html')
    .dialog({
        autoOpen: false,
        title: 'Policies &amp; Terms of Service',
        width: 600,
        height: 400,
        modal: true
    });
Run Code Online (Sandbox Code Playgroud)

另外,请确保$tos_dlg通过类似的方式将DOM 附加到DOM $tos_dlg.appendTo("#containerElement").