在使用renderTo中遇到的Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null

作爲一個ExtJs的初學者,我會遇到很多錯誤,剛剛學習ExtJs我是一點沒有接觸過,不過感覺這個東西學着還是很有意思的

Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null

這個錯誤時我寫進度條時候出現的錯誤,這個問題我研究了一天後來找到我學習那本書配的源碼才找到錯誤,引起這個問題

的原因很多,不過我感覺我這個錯誤對於初學者的我來說確實很難,不過對於學過JavaScript的人來說太不應該了,我在使用

renderTo沒有在<body>標籤內加div,renderTo是要指到一個容器中,希望我這個文章可以幫助和我一樣初學者遇到的問題

<html>
 <head>
  <title>updateText</title>
  <link href="D:ext/resources/css/ext-all.css" rel="stylesheet" type="text/css"/>
  <STYLE TYPE="text/css">
  .newIcon { background-image: url(image/new.gif) !important; }
  .openIcon { background-image: url(image/open.gif) !important; }
  .saveIcon { background-image: url(image/save.gif) !important; }
   </STYLE>
  <script src="D:ext/bootstrap.js"></script>
  <script type="text/javascript">
   Ext.onReady(function(){
  var toolbar = new Ext.toolbar.Toolbar({//創建工具欄
   renderTo:'toolbar',
   width:300
  });

  toolbar.add([//向工具欄中添加按鈕
   {
    text:'新建',//按鈕上顯示的文字
    handler:onButtonClick,//點擊按鈕的處理函數
    iconCls:'newIcon'//在按鈕上顯示的圖標
   },
   {text:'打開',handler:onButtonClick,iconCls:'openIcon'},
   {text:'保存',handler:onButtonClick,iconCls:'saveIcon'}
  ]);

  function onButtonClick(btn){//點擊按鈕時調用的處理函數
   alert(btn.text);//取得按鈕上的文字
  }
 });
  </script>
 </head>
 <body>
  <div id='toolbar'></div>
 </body>
</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章