2010-10-02 98 views
3

嗨每個機構 我正在開發一個MVC應用程序,我想使用Jquery對話框。 我有以下情況: 我有Telerik樹視圖,當我點擊任何節點時,我想要打開對話框並顯示有關此節點的信息。 首先,我添加下面的腳本來初始化對話框:jquery對話框問題

$(document).ready(function() { 
     $("#dialog").dialog("destroy"); 
     $("#dialog-form").dialog({ 
      autoOpen: false, 
      height: 500, 
      width: 500, 
      modal: true, 
      buttons: { 
       Cancel: function() { 
        $(this).dialog('close'); 
       } 
      } 
     }); 
    }); 

然後寫在ONSELECT下面的代碼(Telerik的的客戶端事件)

 $('#dialog-form').dialog('open'); 
     $('#dialog-form').load('<%= Url.Action("SomeAction", "SomeController") %>'); 

在我的母版頁我已經添加腳本文件有必要作出這樣的模式工作:

<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.dialog.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.core.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.widget.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.button.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.draggable.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.position.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.resizable.js") %>"></script> 

,當我在樹的任何節點上單擊發梗Chrome開發人員工具顯示在F ollowing錯誤:

遺漏的類型錯誤:對象#有沒有方法「對話框」

似乎存在與腳本註冊的錯誤或類似的

與此

回答

4

問題解決了...... 當你想使用Telerik的組件在你的意見,你需要註冊腳本管理器腳本是這樣的:

<% Html.Telerik().ScriptRegistrar().DefaultGroup(group => group 
    .Add("jquery-1.4.2.js") 
    .Add("jquery.ui.core.js") 
    .Add("jquery.ui.widget.js") 
    .Add("jquery.ui.mouse.js")  
    .Add("jquery.ui.draggable.js") 
    .Add("jquery.ui.button.js")  
    .Add("jquery.ui.resizable.js") 
    .Add("jquery.ui.dialog.js") 
    .Add("jquery.ui.position.js") 

);
%>

問候

6

你什麼忙一些事情「再需要調整相關性順序所以它是正確的,它應該是:

<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.core.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.widget.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.mouse.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.draggable.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.button.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.position.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.resizable.js") %>"></script> 
<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.dialog.js") %>"></script> 

注加ui.mouse


但是......一個更簡單的方法也只是包括jQuery用戶界面作爲一個單一的文件,如果你使用了它更簡單的組件,易於更新和更少的HTTP請求,例如:

<script type="text/javascript" src="<%: Url.Content("~/Scripts/jquery.ui.js") %>"></script> 

您也可以下載庫作爲一個單獨的文件位置:jQuery UI Download

或從CDN,例如最新的(作爲這個答案的時間)從谷歌:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script> 

對於利益(他們非常相似的好處包括jQuery的本身從CDN )see this question

+0

還是一樣:( – Besher 2010-10-02 12:45:31

+0

@Light - 你應該然後讓在頁面啓動時產生錯誤,少這些腳本只是不正確的目錄中,什麼是你的控制檯說你?應該是得到JavaScript錯誤或404s – 2010-10-02 12:47:30

+0

我相信我的腳本在正確的目錄..控制檯說什麼,但 – Besher 2010-10-03 09:29:18