【问题标题】:InnerHTML issue in IE8 and belowIE8 及以下版本的 InnerHTML 问题
【发布时间】:2012-11-28 20:56:43
【问题描述】:

我正在编辑来自以前开发人员的一些代码,用于时间表过滤系统。我自己解决这个问题的方法是使用 jQuery,所以我在调试这个问题时遇到了一些问题。 IE 中的 Javascript 似乎存在问题。

这是出现问题的代码:

Javascript:

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        document.getElementById("showtimetable").innerHTML=xmlhttp.responseText;
        jQuery('div #moreInfo a').each(function()
{
    var $link = jQuery(this);
    var $dialog = jQuery('<div></div>')
    .load($link.attr('href') + ' #content')
    .dialog
    ({
        autoOpen: false,
        title: $link.attr('title'),
        width: 600
    });

$link.click(function()
{
    $dialog.dialog('open');
    return false;
});

还有标记:

<div id="showtimetable">
<table class="tidytable">
    <thead>
        <tr>
            <th width="20%">
                Venue
            </th>
            <th width="18%">
                Session
            </th>
            <th width="18%">
                Age
            </th>
            <th width="15%">
                <?php echo JText::_('COM_TIMETABLE_HEADING_GROUP'); ?>
            </th>
            <th width="10%">
                <?php echo JText::_('COM_TIMETABLE_HEADING_WEEKDAY'); ?>
            </th>
            <?php /*<th width="13%">
                Activity
            </th>*/ ?>
            <th width="14%">
                Time
            </th>
            <th width="5%">
                Info
            </th>

      </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="13">
                <?php //echo $this->pagination->getListFooter(); ?>
            </td>
        </tr>
    </tfoot>
    <tbody>
        <?php foreach($this->items as $i => $item): ?>
            <tr class="row<?php echo $i % 2; ?>">
                <td>                       
                    <?php if($item->centreDescription!=''){echo '<a href="'.$item->centreDescription.'" >'.$item->centre.'</a>';}
                    else {echo $item->centre;}?>
                </td>                    
                <td>
                    <?php echo $item->class;?>
                </td>
                <td>
                     <?php echo $item->ageRange;?>
                </td>
                <td>
                    <?php echo $item->gn;?>
                </td>
                <td>
                    <?php TimeTablesHelper::getWeekday($item->weekday);?>
                </td>
                <?php /*<td>
                    <?php echo $item->activity; ?>
                </td>*/?>
                <td>
                    <?php echo substr($item->startTime,0,5); ?> - <?php echo substr($item->endTime,0,5); ?>
                </td>
              <td width="5%">
                <?php if($item->bookingInfo!=''){?>
                <div id="moreInfo">
                  <a href="moreinfo.php?id=<?php echo $item->id;?>" title="More Details...">+</a>
                </div>      
                <?php }?>     
              </td>                       
            </tr>              
        <?php endforeach; ?>
    </tbody>
</table>

这是 xml 响应中的内容:

<form action="/component/timetable/" method="post" name="adminForm">
<table class="tidytable">
    <thead>
        <tr>
            <th width="20%">
                Venue
            </th>
            <th width="18%">
                Session
            </th>
            <th width="18%">
                Age
            </th>
            <th width="15%">
                Group           </th>
            <th width="10%">
                Weekday         </th>
                        <th width="14%">
                Time
            </th>
            <th width="5%">
                Info
            </th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <td colspan="13">
            </td>
        </tr>
    </tfoot>
        <tbody>
            <tr class="row0">
                    <td>                       
                        Heywood Civic Centre                     </td>                    
                    <td>
                        50+ Bowls                    </td>
                    <td>
                         Aged 50 plus                    </td>
                    <td>
                        50 Plus                    </td>
                    <td>
                        Thursday                    </td>
                                        <td>
                        13:00 - 16:00                    </td>
                    <td width="5%">
                                        <div id="moreInfo">
                        <a href="/moreinfo.php?id=303" title="More Details...">+</a>
                    </div>      

                    </td>                       
                </tr>              
        </tbody>
    </table>
    <input type="hidden" name="task" value="" />
</form>

这在 Firefox 和 IE9 中运行良好,但在 IE8 及以下版本中,我收到 SCRIPT601:未知运行时错误 Fitness-classes,第 564 行字符 7,它指的是 javascript 中具有 innerHTML 函数的行。

我不确定为什么会出现这个问题,但它会阻止任何 Javascipt 工作。

有人知道为什么会这样吗?

非常感谢!

【问题讨论】:

  • 您能否发布完整的标记,以便更容易找到确切的问题。
  • 嗨,我已经添加了完整的标记和响应标记。

标签: javascript html innerhtml


【解决方案1】:

当您不遵循 W3C 标签建议时会发生此错误。 IE 对此非常挑剔,而 Firefox 则不然。你可以在这里阅读更多内容:http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html

这里有一个类似的问题可能会对您有所帮助:Fixing "unknown runtime error" in IE8

这是同一件事的另一个链接,特别是“表单中的表单”问题:http://jadendreamer.wordpress.com/2009/06/02/internet-explorer-fix-unknown-runtime-error-using-innerhtml-ajax/

【讨论】:

  • 原来是嵌套在表单中的表单导致了问题,因此感谢您使用的链接,我进一步研究并发现这可能是一个问题。
【解决方案2】:

看看这里:http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html

当您尝试插入它不喜欢的 html 时,似乎 IE 会抛出此错误。 xmlhttp.responsetext 中有什么内容?您是否尝试在div 的正下方添加trtd

【讨论】:

  • 您好,感谢您的链接。我已经添加了响应文本,并将通过验证运行它以检查 amy 无效标记。
猜你喜欢
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
  • 2013-06-13
  • 2013-07-05
  • 1970-01-01
  • 2013-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多