2013-06-25 117 views
1

我犯了一個功能appendScript將上一個按鈕單擊事件被稱爲我的功能代碼是遺漏的類型錯誤:未定義是不是一個函數bootstrap.min.js:6

function appendScript() 
{ 
    var v_js; 
    var head= document.getElementsByTagName('head')[0]; 
    v_js = document.createElement('script'); 
    v_js.type = 'text/javascript'; 
    v_js.src = "//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js"; 
    head.appendChild(v_js); 

    var body = document.getElementsByTagName('body')[0]; 
    v_js =document.createElement('script'); 
    v_js.type="text/javascript" ; 
    v_js.src = "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"; 

    body.appendChild(v_js); 
    var v_css = document.createElement('link'); 

    body.appendChild(v_css); 

    interval=self.setInterval(function(){ if(jQuery && typeof $().modal == 'function') 
     { 

      window.clearInterval(interval); 

      //create a div in the body which we will use for our dialog. 
      $(document.getElementsByTagName('body')[0]).append('<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="myModalLabel">Modal header</h3></div><div class="modal-body"><p>One fine body…</p></div><div class="modal-footer"><button class="btn" data-dismiss="modal" aria-hidden="true">Close</button><button class="btn btn-primary">Save changes</button></div></div>'); 

      $('#myModal').modal('show') 
      //setTimeout is non blocking (basically async) so lets put our apex call in a timeout so it doesn't 
      //stop our dialog from showing. 

     } 

    } 
,300);       

} 

和我面對錯誤的是

Uncaught TypeError: undefined is not a function bootstrap.min.js:6 
(anonymous function) bootstrap.min.js:6 
(anonymous function) bootstrap.min.js:6 
+2

也許Bootstrap在jQuery之前加載;將引導腳本初始化設置爲jQuery事件'onload'中的一個函數。另外爲jQuery和Bootstrap嘗試單獨的變量名'v_js'(這可能不是這個問題的原因,但可以肯定)。 – yedpodtrzitko

回答

2

我在代碼中看不到任何問題。 我做了一個簡單的小提琴,其中的代碼工作。

你確定你使用最新的jQuery版本嗎?

您應該嘗試引導程序的debugversion以獲取有關未定義內容的更多信息。

Working sample 

See fiddle

-1

正是我也面臨這個problem.There沒有問題,在您的code..you嘗試加載bootstrap.css和bootstrap.min.css這隻火象未定義功能的問題bootstrap.If你刪除任何引導文件。該錯誤將被清除。

相關問題