<head>
<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("note.xml");
document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}
</script>
</head>
<body onload="parseXML()">
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span> </p>
</body>XML的代码
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <!-- Copyright w3school.com.cn
-->
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>我的xml和html页面是放在同一目录下的
为什么显示不了呢?
有提示是SCRIPT5007: 无法获取属性“nodeValue”的值: 对象为 null 或未定义
<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("note.xml");
document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}
</script>
</head>
<body onload="parseXML()">
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span> </p>
</body>XML的代码
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <!-- Copyright w3school.com.cn
-->
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>我的xml和html页面是放在同一目录下的
为什么显示不了呢?
有提示是SCRIPT5007: 无法获取属性“nodeValue”的值: 对象为 null 或未定义
解决方案 »
- JS 如何获取div的兄弟div
- 谁能帮忙简化一下代码?? 关于"显示/隐藏层"
- 急!!如何从数据库读取记录生成联动菜单
- 像baidu那种在文本框中输入内容后,会自动检索相应内容的效果怎么实现?
- setInterval调用的函数中加document.write不能执行?
- 来帮忙看下这个问题怎么弄!!!
- 一个动态生成不同坐标DIV的问题,js高手进
- 小问题,请大家帮忙解决一下,在线等,解决马上送分。
- help :谁能看出网络名片网上www.gonamecard.com的名片选择是如何做的?我也想做这样的
- 敲了一晚上!为什么我两个函数运行不起来?!主要是setInterval('timer()',100);setInterval('runClock()',100)
- table 嵌套问题
- 高手们,速度啊,在线等。。。急急急。。。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Copyright w3school.com.cn -->
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>你上面的有语法错误。