javascript - IE8 及以下版本中的 InnerHTML 问题

标签 javascript html innerhtml

我正在为时间表过滤系统编辑以前开发人员的一些代码。我自己解决这个问题的方法是使用 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: unknown runtime error fitness-classes, line 564 character 7 它指的是 javascript 中带有 innerHTML 函数的行。

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

有人知道为什么会发生这种情况吗?

非常感谢!

最佳答案

如果您不遵循 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/

关于javascript - IE8 及以下版本中的 InnerHTML 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817999/

相关文章:

javascript - 打开的网络套接字连接是否阻止了 ajax 请求?

javascript - 一般来说,在 javascript 中,使用innerHTML 不是一个安全问题吗?

javascript - 'innerHTML' : object is null or undefined

javascript - 如何禁用谷歌 360 旅游滚动缩放?

javascript - CSS3动画的问题

html - 在 Blogger 上居中导航栏

html - CSS 文本叠加在完整图像上

javascript - 无法更改表格的内部 HTML

javascript - 在 AngularJS 插值中将时间戳转换为日期格式

javascript - 如何在 react 中用鼠标滚轮水平滚动表格?