我需要通过 AJAX 获取js.htm里的内容var xmlHttp;
if (window.xmlHttpRequest) { //兼容Mozilla、Safari等浏览器对象
xmlHttp = new xmlHttpRequest();
}else{
xmlHttp = new ActiveXObject("Msxml2.xmlHttp");
}
xmlHttp.open("GET", "js.htm", false);
xmlHttp.send();
document.getElementById("a1").innerHTML=xmlHttp.responseText;
js.htm 文件里的代码是:<script language="javascript">document.write("hello");</script>
world
但是我最后获得的只有字符“world”,却没能得到字符“hello”。
是不是不能这样操作呢?
if (window.xmlHttpRequest) { //兼容Mozilla、Safari等浏览器对象
xmlHttp = new xmlHttpRequest();
}else{
xmlHttp = new ActiveXObject("Msxml2.xmlHttp");
}
xmlHttp.open("GET", "js.htm", false);
xmlHttp.send();
document.getElementById("a1").innerHTML=xmlHttp.responseText;
js.htm 文件里的代码是:<script language="javascript">document.write("hello");</script>
world
但是我最后获得的只有字符“world”,却没能得到字符“hello”。
是不是不能这样操作呢?
document.getElementById("a1").innerHTML =data[1];
eval(data[0]);//用eval会将字符串当作一个JavaScript表达式
js.htm改变一下document.write("hello");|
world
Firefox 里没有效果!
前面加
alert(xmlHttp.responseText);
看看就知道了,内容都已经获得了,只不过有一点
<script language="javascript">document.write("hello");</script>
是字符串,所以肯定不会被当作JS执行,其中含<xxx>的会被IE仅当作HTML元素对待,所以看不到了,(script换成span)肯定看到其中的内容了,
这个属性是解析标签的 所以不《script>标签是不会显示的 另外设置这个属性也不会 自动运行里面的js