【问题标题】:Can not display html content into Jquery dialog无法在 Jquery 对话框中显示 html 内容
【发布时间】:2013-10-29 03:45:49
【问题描述】:

我有一些 html 内容要在 jquery 对话框 onclick 中显示。这是示例代码

html 代码(在 php 内):

<div id = '".$id."' style='display:none' >".$toperrors." </div> 
<td align='center' onclick='toperrors($id);' > <img src='images/minimize.jpg' width=30     
height=20 ></img> </td> 

jQuery :

function toperrors(str){
$("#dialog").html("");
 $("#dialog").html($("div#"+str).html());
   $("#dialog").dialog({
   title: "Top errors",
    modal: true,
    width: "800px",
     height: 400,
  buttons: 
 {"OK":function() {
 $(this).dialog("close");
  }
 }
 });
  }

如果 $toperrors 包含一个字符串,则代码运行良好,没有任何问题。

但是如果我将 html 内容分配给 $toperrors 变量。然后是网页上打印的 html 内容
页面本身。也许它没有隐藏在 div 中的 style='display:none' 中。 任何帮助将不胜感激。谢谢。

【问题讨论】:

  • 你不应该给一个 html id 任何东西,而不是一个纯字符串。否则你迟早会遇到问题..
  • 您能否举一个导致此行为的 html 输出示例?
  • 由于复制粘贴,HTML 内容不是正确的 html 内容。我正在使用一些 html 净化器。但格式在网页上打印正常。由于我公司的保密协议,我无法显示输出,抱歉。
  • 好吧,我猜在这种情况下,输出会破坏 html 结构,因此 css 无法正确定位您的 div,因此内容会显示而不是隐藏。
  • 是的,你说的对我来说很有说服力。知道如何克服吗?

标签: javascript php jquery html dialog


【解决方案1】:

strip_tags() 或 htmlentities()

<div id = '".strip_tags($id)."' style='display:none' >".$toperrors." </div> 

【讨论】:

  • 您好,感谢您的快速回复。但这没有帮助。抱歉,$toperrors 是包含 html 内容的变量,而不是 $id。似乎当 $toperrors 具有在浏览器上打印的 html 内容时。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多