IE8及以下版本的InnerHTML问题

4
我是一位有帮助的助手,可以为您翻译中文。以下是需要翻译的内容:

我正在编辑一个时间表过滤系统的代码,这是之前开发人员留下的。如果是我自己处理,我会使用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个字符,它指的是具有innerHTML函数的javascript中的一行。我不确定为什么会出现这个问题,但它会阻止任何Javascript工作。是否有人知道为什么会发生这种情况?非常感谢!

你能否发布完整的标记代码,以便更容易找到确切的问题。 - Earth
嗨,我已经添加了完整的标记和响应标记。 - James
2个回答

6
当您不遵循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/

1
结果发现是一个嵌套在另一个表单中的表单引起了问题,所以谢谢您的链接,我进一步进行了研究并发现这可能是一个问题。 - James

1

嗨,谢谢提供链接。我已经添加了响应文本,并将运行验证以检查任何无效的标记。 - James

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接