【问题标题】:How to Append html code inside dialog using jquery如何使用jquery在对话框中附加html代码
【发布时间】:2014-10-30 13:34:11
【问题描述】:

我有这个变量template="<div>...</div>"

我想在对话框中显示这段 html 代码:

<div id="dialog" title="Basic dialog">
    <p id="templates"></p>
</div>

<script>
    $("#templates").html(template);
    $( "#dialog" ).dialog({
       height: auto,
       width: 800,
       modal: true,
       // ...
    });
</script>

但它不起作用。

如何在对话框中附加我的自定义 html?

【问题讨论】:

  • 您正在尝试将"&lt;html&gt;&lt;head&gt;...&lt;/head&gt;&lt;/html&gt;" 添加到&lt;p&gt;。你是认真的吗?您可以为此使用&lt;iframe&gt;。或者可能更简化(只是&lt;body&gt; 内部HTML)模板和&lt;div&gt; 而不是&lt;p&gt;
  • "我有这个变量 template="..." 我想在对话框中显示这个 html 代码:"不,你不要'不想那样。我认为您误解了您要完成的工作。
  • @Regent 我错了...谢谢...;)!!!

标签: jquery html dialog


【解决方案1】:

这应该适用于您的目的:

function PopModal(StuffToAppearInModal) {
              $('<div>' + StuffToAppearInModal+ '</div>').dialog({
              height: auto,
              width: 800,
              modal: true,
                });
            }

从变量中删除“head”和“html”标签,并像这样调用它:

 PopModal("hey this is going to appear in my <font color='Red'>modal</font>.  html controls work, too like this: <input type='text' id='tbTest'/>");

【讨论】:

    【解决方案2】:

    您可以使用wireframes 或附加代码而不使用&lt;html&gt;&lt;head&gt;...&lt;/head&gt;&lt;/html&gt;,因为它被确定为网页。

    【讨论】:

      【解决方案3】:

      只有有效的 html 内容才会被解释为 html 函数内的参数。如果没有,它将被过滤。在您的示例过滤器中,仅在您的内容中留下“...”。

      有关其他(有效)html 内容,请参阅 example

      var template="<table style=\"border:solid red 2px;\"><tr><td><u>Test</u></td></tr></table>";
      $("#templates").html(template);
      ...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-12
        相关资源
        最近更新 更多