javascript IE8 及以下的 InnerHTML 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13817999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
InnerHTML issue in IE8 and below
提问by Jim
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.
我正在编辑来自以前的开发人员的一些代码,用于时间表过滤系统。我自己解决这个问题的方法是使用 jQuery,所以我在调试这个问题时遇到了一些问题。IE 中的 Javascript 似乎存在问题。
Here is the code where the issue is arising:
这是出现问题的代码:
The 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;
});
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:
这是 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>
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.
这在 Firefox 和 IE9 中工作正常,但在 IE8 及更低版本中,我收到 SCRIPT601: unknown runtime error适应类,第 564 行字符 7,它指的是具有 innerHTML 函数的 javascript 中的行。
I am unsure as to why this issue may be arising but it is preventing any of the Javascipt from working.
我不确定为什么会出现这个问题,但它阻止了任何 Javascipt 工作。
Does anybody have any idea why this would be occurring?
有谁知道为什么会发生这种情况?
Many thanks in advance!
提前谢谢了!
回答by Niklas
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
当您不遵循 W3C 标记建议时会发生此错误。IE 对此非常挑剔,而 Firefox 则不然。您可以在此处阅读更多信息: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
这是一个可能对您有所帮助的类似问题: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/
这是关于同一件事的另一个链接,特别是“表单中的表单”问题:http: //jadendreamer.wordpress.com/2009/06/02/internet-explorer-fix-unknown-runtime-error-using-innerhtml -ajax/
回答by Tetaxa
Have a look here: http://blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html
看看这里:http: //blog.rakeshpai.me/2007/02/ies-unknown-runtime-error-when-using.html
Seems that IE will throw this error when you try to insert html that it doesn't like there. What's in xmlhttp.responsetext
? Are you trying to add a tr
or td
directly beneath the div
perhaps?
当您尝试插入它不喜欢的 html 时,IE 似乎会抛出此错误。里面有什么xmlhttp.responsetext
?您是否要在tr
或td
正下方添加或div
?