您现在的位置是:首页 > 电脑技术查询 > web开发

getElementsByTagName在IE下取值有关问题

编辑:chaxungu时间:2022-10-02 23:18:02分类:web开发

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 codefunction 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; } }}