简体   繁体   English

IE中的innerHTML?

[英]innerHTML in IE?

I'm having trouble using innerHTML with my radio type button. 我在使用单选按钮时无法使用innerHTML。

<table align="center">
 <div class='main'>
  <span id="js" class='info'>
   <label><input type="radio" name="js" value="0" size="<?php echo $row['size']; ?>" onclick="js(this.value, this.size);" /><img src="arrowup.png"/></label>
   <br />
   <label><input type="radio" name="js" value="1" size="<?php echo $row['size']; ?>" onclick="js(this.value, this.size);" /><img src="arrowdown.png"/></label>
  </span>
 </div>
</table>

My .js looks like this: 我的.js看起来像这样:

var xmlhttp;

function getVote(a,b) {
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)   {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="js.php";
url=url+"?js="+a;
url=url+"&id="+b;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged() {

  if (xmlhttp.readyState==4) {
  document.getElementById("js").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject() {
var objXMLHttp=null;
if (window.XMLHttpRequest)   {
  objXMLHttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)   {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
return objXMLHttp;
} 

This doesn't work in IE only! 这仅在IE中不起作用! Any help? 有什么帮助吗?

firstly, pretty sure a DIV directly inside a TABLE is illegal markup. 首先,很确定直接在TABLE内部的DIV是非法标记。

don't use illegal markup. 不要使用非法标记。 browsers will respond differently to it (i've recently had Opera ignore some illegal stuff with IE trying to render it). 浏览器对它的响应会有所不同(我最近让Opera忽略了IE试图渲染它的一些非法行为)。

tho IE usually deserves it, firstly get the markup correct and then see how IE does. IE通常应得到它,首先获得正确的标记,然后查看IE的工作方式。 it may be that it has failed to render the DOM how you expect. 可能是由于未能按预期方式呈现DOM。

(FWIW there is an innerHTML rendering problem i've run up against with IE, http://support.microsoft.com/kb/276228/ , but for the SELECT element so i don't think it applies here). (FWIW在IE中遇到了一个innerHTML渲染问题, http://support.microsoft.com/kb/276228/ ,但是对于SELECT元素,所以我认为它在这里不适用)。

The issue was indeed innerHTML on table tag. 问题的确是表格标记上的innerHTML。 IE doesn't support innerHTML wrapped around a table tag nor they intend to resolve this issue in their future releases. IE不支持包装在表格标签周围的innerHTML,也不打算在将来的版本中解决此问题。

The workaround is to either use DOM methods or the easiest way: wrap your table around a div. 解决方法是使用DOM方法或最简单的方法:将表包装在div周围。

So I ended up with: 所以我最终得到了:

<div id="js" align="center"><table>
        <span class='main'>
            <a onClick="getVote(this.value, this.size);" type="radio" value="0" size="<?php echo $row['id']; ?>" /><img src="arrowup.png"/></a>
            <br /><a onClick="getVote(this.value, this.size);" type="radio" value="1" size="<?php echo $row['id']; ?>" /><img src="arrowdown.png"/></a>
            </span>
</table></div>

There's another IE bug that screws up the label if they're set to be image. 如果设置为图像,还有另一个IE错误会弄乱标签。 Just a heads up! 只是一个提示! I know you won't be surprised when I say IE sucks! 我知道当我说IE很烂时,您不会感到惊讶!

我知道这有点晚了,但是这是如何使用jQuery解决此问题:

$("#tableName").html(DataToWrite);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM