2014-08-31 27 views
0

我想在我的應用程序中使用jquery對話框,但它不會工作,它說類型錯誤:$(...)。對話框不是從Mozilla控制檯的功能,這是我的代碼jquery對話框不是函數

<link rel="stylesheet" href="css/jquery-ui.css"> 
<script src="js/jquery.js"></script> 
<script src="js/jquery-ui.js"></script> 



<div id="dialog-message" title="Important information"> 
    <div style="margin-left: 23px;"> 
     <p> 
      We're closed during the winter holiday from 21st of December, 2010 until 10th of January 2011. 
     </p></div> 
</div> 

<script > 
    $(function() { 

     $("#dialog-message").dialog({ 
      modal: true, 
      draggable: false, 
      resizable: false, 
      position: ['center', 'center'], 
      width: 500, 
      height: 250, 
      dialogClass: 'ui-dialog-osx', 
      buttons: { 
       "I've read and understand this": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 

    }); 
</script> 

我的工作,它使用其他JavaScript庫,並避免衝突的應用程序,我把我的對話框腳本後,使用jQuery的文件,但仍是同樣的問題。可能是什麼問題?

+0

1)*搜索*的錯誤信息2)*正確加載插件(它可能無法加載所述腳本資源;檢查網絡活動) – user2864740 2014-08-31 09:06:35

+0

http://stackoverflow.com/questions/3791781/jquery -ui-dialog-is-not-a-function-error,http://stackoverflow.com/questions/24402531/whats-wrong-with-this-code-dialog-is-not-a-function,http:/ /stackoverflow.com/questions/6710041/elrte-dialog-is-not-a-function-error – user2864740 2014-08-31 09:07:29

回答

2

由於大部分的JavaScript庫所使用的美元符號$操作其功能,包括不同的JavaScript使衝突,因此要避免這個問題,並解決問題,我用這個jQuery功能,它的工作原理

 var $j = jQuery.noConflict(); 

然後使用附加$ J,而不是$這樣的:

 $j(function() { 

    $j("#dialog-message").dialog({ 
     modal: true, 
     draggable: false, 
     resizable: false, 
     position: ['center', 'center'], 
     width: 500, 
     height: 250, 
     dialogClass: 'ui-dialog-osx', 
     buttons: { 
      "I've read and understand this": function() { 
       $j(this).dialog("close"); 
      } 
     } 
    }); 

}); 

它工作沒有錯誤。

0

請確認:

  1. jQuery的ui.js正在運行Web服務器通過應用程序加載(HTTP)。在Firefox的本地調試器下的標籤'網絡'或在'網絡'下的Firebug。

  2. ,並驗證jQuery的ui.js有「對話」模塊

+0

我試圖從網上使用這個腳本,和同樣的問題, 我在分頁中使用了我的代碼,它工作正常,但是在我的應用程序中使用它時,它無法工作。 – 2014-08-31 09:17:01

+0

在應用程序中使用了所有其他JS庫嗎?如果託管,請分享網址,否則僅根據推定進行調查很困難。 – Ovais 2014-09-01 05:27:48