日期:2014-05-16  浏览次数:20357 次

getElementsByTagName在IE下取值问题
<?xml version="1.0" encoding="UTF-8"?>
<request>
  <city>zk</city>  
  <tab id="a1">www</tab>
  <tab id="ab">error</tab>
<request>

js
function disp(doc,id){  
  $('mainlist').innerHTML=doc.getElementsByTagName('tab')[id].firstChild.nodeValue;  
}
上面的代码如果在ff中可以正常取到值,但在ie中没办法了,哪位有好的方法解决

------解决方案--------------------
不知道doc你这个是什么对象,我用的是xmlhttp

<?xml version="1.0" encoding="UTF-8"? > 
<request > 
<city >zk </city >
<tab>www </tab > 
<tab>error </tab > 
<request >

var a1=xmlHttp.responseXMl.getElementsByTagName("tab")[0].firstChild.data;
var a2=xmlHttp.responseXMl.getElementsByTagName("tab")[1].firstChild.data;
------解决方案--------------------
很有可能,ie兼容不高,你最好用兼容的方法做:)
------解决方案--------------------
用DOM来解析吧
JScript code

function disp(doc,id){
     for (var i = 0; i < doc.getElementsByTagName( 'tab ').length; i++)
     {     
          if (doc.getElementsByTagName( 'tab ')[i].getAttribute("id") == id)
          {
               $( 'mainlist ').innerHTML = doc.getElementsByTagName( 'tab ')[i].firstChild.nodeValue;
               break;
          }
     }
}