最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Onload event not working with Internet Explorer - Stack Overflow

programmeradmin1浏览0评论

I've written some very simple code on Internet Explorer 8 and I don't understand why nothing happens when I open the page with IE (why the text 'test' doesn't appear on the page).

I've tried on Firefox and Chrome and it works perfectly.

my code :

<html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso 8859-1" />

   <script type="text/javascript">

   function display() {
      output.innerHTML+='test';
   }

   </script>

   </head>

   <body onload="display()">

      <div id="output">
      </div>
   </body>
</html>

Edit : let IE change your setting, don't do it by hand or it gets weird :-))

I've written some very simple code on Internet Explorer 8 and I don't understand why nothing happens when I open the page with IE (why the text 'test' doesn't appear on the page).

I've tried on Firefox and Chrome and it works perfectly.

my code :

<html>
   <head>
   <meta http-equiv="Content-Type" content="text/html; charset=iso 8859-1" />

   <script type="text/javascript">

   function display() {
      output.innerHTML+='test';
   }

   </script>

   </head>

   <body onload="display()">

      <div id="output">
      </div>
   </body>
</html>

Edit : let IE change your setting, don't do it by hand or it gets weird :-))

Share Improve this question edited May 11, 2011 at 13:57 Bruno asked May 11, 2011 at 13:36 BrunoBruno 9,10713 gold badges40 silver badges55 bronze badges 4
  • As mentioned in the answers already, document.getElementById is the usual method of getting a handle on an element from the document. Does this work for you; jsbin./uqama4? It works for me on Vista/IE 8 – Andy E Commented May 11, 2011 at 13:40
  • I would re-install IE 8, or upgrade to IE 9. – Andy E Commented May 11, 2011 at 13:45
  • Works fine in IE8 for me. Have you turned JS off in your installation of IE or something? – ADW Commented May 11, 2011 at 13:49
  • 1 one thing that pops in my mind is active x is not enabled or JS disabled – KJYe.Name Commented May 11, 2011 at 13:52
Add a ment  | 

2 Answers 2

Reset to default 3
document.getElementById('output').innerHTML += 'test';

Try:

   function display() {
      document.getElementById('output').innerHTML+='test';
   }
发布评论

评论列表(0)

  1. 暂无评论