[已经完美解决]IE下 'document.getElementById(...)' is null
生活随笔
收集整理的這篇文章主要介紹了
[已经完美解决]IE下 'document.getElementById(...)' is null
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
View Code 1 $.ajax({
2 type: "POST",//請(qǐng)求方式
3 url: "text.txt",//地址,就是action請(qǐng)求路徑
4 cache:false,
5 data: "text",//數(shù)據(jù)類型text xml json script jsonp
6 success: function(msg){//返回的參數(shù)就是 action里面所有的有g(shù)et和set方法的參數(shù)
7 document.getElementById("result").innerHTML=msg;
8 alert(document.getElementById("result"));
9 }
10 });
<script src="ajax.js"></script>
2 type: "POST",//請(qǐng)求方式
3 url: "text.txt",//地址,就是action請(qǐng)求路徑
4 cache:false,
5 data: "text",//數(shù)據(jù)類型text xml json script jsonp
6 success: function(msg){//返回的參數(shù)就是 action里面所有的有g(shù)et和set方法的參數(shù)
7 document.getElementById("result").innerHTML=msg;
8 alert(document.getElementById("result"));
9 }
10 });
以上代碼,在FF下沒有問題,但是在IE下會(huì)報(bào):?'document.getElementById(...)'? is null錯(cuò)誤
goolge+baidu了一下,比較靠譜的是說頭文件的生命的加一行,將IE8模式強(qiáng)制切換到IE7模式
照做后無果,問題依舊,然后想到既然沒找到或者為空,說明沒找到該標(biāo)簽,所以,將該JS的引用放到標(biāo)簽下面,OK,問題解決:
<div id="result"></div><script src="ajax.js"></script>
思考真重要!
轉(zhuǎn)載于:https://www.cnblogs.com/lonelyDog/archive/2012/03/31/2426769.html
總結(jié)
以上是生活随笔為你收集整理的[已经完美解决]IE下 'document.getElementById(...)' is null的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 翻译: Waf 教程
- 下一篇: 【Struts2+Spring3+Hib