【发布时间】: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