IE8及以下版本中的InnerHTML问题 [英] InnerHTML issue in IE8 and below

查看:118
本文介绍了IE8及以下版本中的InnerHTML问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



以下是出现问题的代码:



<如果(window.XMLHttpRequest)
{//代码为IE7 +,Firefox,Chrome, Opera,Safari
xmlhttp = new XMLHttpRequest();
}
else
{//代码为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('<
.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 width =18%>
Session
< th>
< th width =18%>
年龄
< / 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%>
活动
< / th> * /?>
< th width =14%>
时间
< / th>
< th width =5%>
信息
< / 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-> '< / a>';}
else {echo $ item-> center;}?>
< / 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 =更多详情...> +< / a>
< / div>
<?php}?>
< / td>
< / tr>
<?php endforeach; ?>
< / tbody>
< / table>



这里是xml响应:

 < form action =/ component / timetable /method =postname =adminForm> ; 
< table class =tidytable>
< thead>
< tr>
< th width =20%>
地点
< / th>
< th width =18%>
Session
< / th>
< th width =18%>
年龄
< / th>
< th width =15%>
组< / th>
< th width =10%>
星期几< / th>
< th width =14%>
时间
< / th>
< th width =5%>
信息
< / th>
< / tr>
< / thead>
< tfoot>
< tr>
< td colspan =13>
< / td>
< / tr>
< / tfoot>
< tbody>
< tr class =row0>
< td>
海伍德文娱中心< / td>
< td>
50+碗< / td>
< td>
50岁以上< / td>
< td>
50加< / td>
< td>
星期四< / td>
< td>
13:00 - 16:00< / td>
< td width =5%>
< div id =moreInfo>
< a href =/ moreinfo.php?id = 303title =更多详情...> +< / a>
< / div>

< / td>
< / tr>
< / tbody>
< / table>
< input type =hiddenname =taskvalue =/>
< / form>

在Firefox和IE9中可以正常工作,但在IE8及以下版本中,我收到一个SCRIPT601:未知的运行时错误健身类,第564行第7个字符,它引用javascript和innerHTML函数中的行。



我不确定这个问题可能会出现,但它是阻止任何Javascipt工作。



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

非常感谢您!

解决方案

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



以下是一个类似的问题,可以帮助你:修复未知运行时错误在IE8中



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


I am editing some code from a previous developer for a timetable filtering system. The way I would tackle this myself is using jQuery so I am having a few issues debugging this problem. There seems to be an issue with the Javascript in IE.

Here is the code where the issue is arising:

The 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;
});

And the markup:

<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>

Here is what is in the xml response:

<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>

This works fine in Firefox and IE9 but in IE8 and below I am recieving a SCRIPT601: unknown runtime error fitness-classes, line 564 character 7 which refers to the line in the javascript with the innerHTML function.

I am unsure as to why this issue may be arising but it is preventing any of the Javascipt from working.

Does anybody have any idea why this would be occurring?

Many thanks in advance!

解决方案

This error occurs when the you don't follow the W3C tag recommendations. IE is very picky about this and Firefox is not. You can read more here: http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html

Here's a similar question that might help you: Fixing "unknown runtime error" in IE8

Here's another link on the same thing, and specifically the "form within a form" issue: http://jadendreamer.wordpress.com/2009/06/02/internet-explorer-fix-unknown-runtime-error-using-innerhtml-ajax/

这篇关于IE8及以下版本中的InnerHTML问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆