<?xml version = "1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en">
<head>
<title>Finding Element Values in an XML Document</title>
<script language = "javascript" type = "text/javascript">
function getStudentData(){
var xmlDoc;
xmlDoc = new ActiveXOjbect("Microsoft.XMLDOM");
xmlDoc.load("School.xml");
nodeSchool = xmlDoc.documentElement;
nodeClass = nodeSchool.firstChild;
nodeStudents = nodeClass.lastChild;
nodeStudent = nodeStudents.lastChild;
nodeFirstName = nodeStudent.firstChild;
nodeLastName = nodeFirstName.nextSibling;
outputMessage = "Name: " + nodeFirstName.firstChild.nodeValue + " " + nodeLastName.firstChild.nodeValue;
message.innerHTML = outputMessage;
}
</script>
</head>
<body>
<center>
<h1>Finding Element Values in an XML Document</h1>
<div id = "message"></div>
<p>
<input type = "button" value = "Get Second Student's Name" onClick = "getStudentData()" />
</p>
</center>
</body>
</html>
它给出了这样的错误
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2) Timestamp: Fri, 11 Jan 2013 14:33:05 UTC
Message: 'ActiveXOjbect' is undefined Line: 19 Char: 5 Code: 0 URI: file:///D:/Priyal/Personal/Programing/XHTML/XML/School.html
Message: 'ActiveXOjbect' is undefined Line: 19 Char: 5 Code: 0 URI: file:///D:/Priyal/Personal/Programing/XHTML/XML/School.html
最佳答案
您有一个拼写错误。
将 ActiveXOjbect
替换为 ActiveXObject
。
但您还应该注意,ActiveXObject
仅在 Internet Explorer 中可用。所有其他浏览器都会抛出相同的错误。
关于javascript - 消息: 'ActiveXOjbect' is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14280319/