0

好的,所以基本问题是在设置 div 元素的 innerHTML 时,我的字符串中的任何 html 标记都在除 Firefox 之外的所有主要浏览器中被剥离(并且不显示)。现在要注意的是,第一次加载页面时不会发生这种情况,它只会在部分回发时发生(除非它的 Firefox,否则它总是有效的)。

我正在尝试运行一个脚本(实际上是通过 ScriptManager 从后面的代码创建和添加的)以将一些 html 元素(带有事件处理程序)添加到一些已经存在的 html 元素中。我知道脚本总是在运行,即使我有问题,因为我可以核对现有元素的 html 或设置一些文本。我什至可以拥有文本和标记,但不会在文本呈现时呈现标记,除非文本在标记内。所以:

someElement.innerHTML = "Blah blah blah" -- 有效

someElement.innerHTML = " <br/><br/>Blah blah blah<br/><br/>"

Blah blah blah 显示但没有中断

someElement.innerHTML = " <p>This will disappear</p><div>So will this</div>"

所有这些文本将与标记一起消失。哦,我考虑过以“标准”方式执行此操作,即 document.createElement 等,但我遇到了完全相同的问题。

如果您需要/想知道其他任何事情,请询问。

编辑:当我说主要浏览器时,我的意思是:Safari 4.0.3、Chrome 3.0.195.27 和 IE 8.0.6

完整的 javascript(与此功能相关)。如果有格式错误是因为这实际上是 C# 中的一个字符串,所以为了清楚起见,我试图删除一堆时髦的转义废话。

var overflowEls = getElementsByClass("descriptionBox");

for (var i = 0; i < overflowEls.length; i++)
{
    if (checkOverflow(overflowEls[i]))
    {
        var html = overflowEls[i].innerHTML;
        overflowEls[i].innerHTML = overflowEls[i].innerHTML = "<div class="videoFeedDescriptionButtons" onclick="expand(this);">+</div><br/><div onclick="collapse(this);" class="videoFeedDescriptionButtons">-</div>" + html;              

    }
}

周围的 html,请记住它是从 youtube 提要中提取的,然后由 .net 转发器控件生成:

<td valign="top" style="margin: 5px 5px 5px 5px;height:auto;">
  <div class="descriptionBox" style="max-height:100px; overflow:hidden;" >
    <b>
    THE WORLDS BIGGEST PLANES!! by kieran smith</b><br />
    <br />
    by Antonov (ASTC). It was designed for the Soviet space program as a replacement for the Myasishchev M-4 'Bison' for the purpose of carrying the Energia     rocket boosters and to also be able to carry the Buran space shuttle in piggy-back mode much the same as the American Shuttle Carrier Aircraft.The An-225     first flew on 21 December, 1988. Only one An-225 is currently in service. It is commercially available for carrying ultra heavy and/or oversize freight. It     can carry up to 227 metric ...<br />
  </div>
  <a id="ctl00_ContentPlaceHolder1_Repeater1_ctl01_lnView" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl01    $lnView','')">View</a>&nbsp;&nbsp;<a id="ctl00_ContentPlaceHolder1_Repeater1_ctl01_lnAdd" 

  href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Repeater1$ctl01$lnAdd','')">Add</a>
 <br />

4

2 回答 2

0

也许您#someElement * { display: inline !important }的 CSS 中可能有或类似的东西。

于 2009-10-15T23:16:29.827 回答
0

事实证明,脚本管理器以某种方式多次将脚本添加到页面。有点。我之所以这么说,是因为它输出的脚本中还有一些 C# 格式的东西。这是它的样子:

<script type="text/javascript">

"var overflowEls = getElementsByClass("descriptionBox"); for (var i = 0; i < overflowEls.length; i++) { if (checkOverflow(overflowEls[i])) { var html = overflowEls[i].innerHTML; overflowEls[i].innerHTML = overflowEls[i].innerHTML = "

<div class="\"onclick="\">+</div>

<div onclick="\"collapse(this);\""class="\"videoFeedDescriptionButtons\"">-</div>
"" + html;}}"

</script>

As you can see, a total mess. Anyhow,I 'solved' this by moving the script to the aspx page as a function and just having the scriptmanager output a call to the function, so now I've got an ever increasing number of function call scripts in the html head. The script does work now so I'm going to mark this as answered and open a new question to try to figure out why the scriptmanager is adding duplicates.

于 2009-10-16T17:04:47.193 回答