下面的XML解析是一位大哥写给我的,但在我本机IE浏览器运行没效果,望各位大虾看看是什么问题
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLDOM');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ (new Date()).getTime(), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<div>
<img src="boom.jpg"></img>
</div>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLDOM');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ (new Date()).getTime(), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<?xml version="1.0" encoding="utf-8"?>
<div>
<img src="boom.jpg"></img>
</div>
解决方案 »
- (js)单引号 和双引号 有什么区别?
- 求助!!用js实现div从iframe内嵌页输出到iframe外层页面的定位问题
- 这个特效很常见...我想知道怎样实现它的?
- 如何得到框架的网址?
- 诸位帮我看看
- 情人节来了,非常急着送分,如何发邮件?请诸位指点
- cookie文件是否有2k的限制,如何实现超过2k的cookie!
- jquery设置全局变量问题
- datatable分页问题,下一页不显示文字
- 两个js方法是一样的 都是拼接相同的html 但是id有的不同 怎么抽出一个公共方法,然后传入不同的id生成html
- Venkman JavaScript Debugger在firefox中调试时,document.title得到的总是"JavaScript Debugg"
- javascript 小数问题
<html>
<head>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (document.all){
try {return new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){return new ActiveXObject('Microsoft.XMLHTTP');};
}
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'info.xml?r='+ escape(new Date()), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
<head>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
function creatXHR(){
if (document.all){
try {return new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){return new ActiveXObject('Microsoft.XMLHTTP');};
}
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
}
function getText(node){
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
}
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}
</script>
</head>
<body>
<div id="aa" onClick="a();" style="width:400px; height:400px; background-color:#0066FF;"></div>
<script type="text/javascript">
function a(){
var xhr = creatXHR();
xhr.open('GET', 'image-flow.xml?r='+ escape(new Date()), false);
xhr.send(null);
try {
done(xhr);
} catch (e) {
xhr.onreadystatechange = function(){
if (xhr.readyState == 4 && xhr.status == 200) {
done(xhr);
}
}
}
}
</script>
</body>
</html>
如果去掉try catch 判断,直接done(xhr),就会报以下行缺少对象的错误。
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);
把
function done(xhr){
var text = getText(xhr.responseXML.getElementsByTagName('div')[0]);
document.getElementById("aa").innerHTML = text;
}改成 function creatXHR(){
if (window.ActiveXObject) return new window.ActiveXObject('Microsoft.XMLHTTP');
else if (window.XMLHttpRequest) return new window.XMLHttpRequest();
else return null;
} function done(xhr){
var text = xhr.responseXML.getElementsByTagName("div")[0].childNodes[0].xml;
document.getElementById("aa").innerHTML = text;
}
没,调用getText()函数,执行以下语句就断了
return node.xml ? node.xml : (new XMLSerializer()).serializeToString(node);所以alert(text)没有效果
不是,是C:\Documents and Settings\Administrator\桌面\7657252.html
FF,SAFARI都是file:///C:/Documents%20and%20Settings/Administrator/%E6%A1%8C%E9%9D%A2/7657252.html方式请问怎么调运行方式?调成这个或者http://localhost/xx.html这种方式
当然要建立服务器