2014-09-05 27 views
0

我在我的智慧結束了。我的頁面上有一個鏈接,用於將PartialView的內容作爲可拖動模式加載到我的頁面上的<div>。該Javascript代碼內容加載到一個div的作品,但我的回調創建模式失敗,出現以下錯誤:jquery ui - undefined不是對話框上的功能

<head> 
    <meta charset="utf-8" /> 
    <title></title> 
    <link href="/favicon.ico" rel="shortcut icon" type="image/x-icon" /> 
    <meta name="viewport" content="width=device-width" /> 

    <script src="/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script> 
    <script src="/Scripts/jquery-ui-1.8.24.min.js"></script> 
    <script src="/Scripts/modernizr-2.6.2.js"></script> 
    <script type="text/javascript" src="/Scripts/jquery.dataTables.min.js"></script> 

    <link href="/Content/siteV2.css" rel="stylesheet"/> 
    <link rel="stylesheet" type="text/css" href="/Content/jquery.dataTables.min.css" /> 

</head> 
:從作爲我_Layout.cshtml文件中定義的HTML頭

> Uncaught TypeError: undefined is not a function 
> jquery-1.8.2.min.js:19p.fn.extend.add 
> jquery-1.8.2.min.js:19p.fn.extend.addBack 
> jquery-1.8.2.min.js:19a.widget._getHandle 
> jquery-ui-1.8.24.min.js:23a.widget._mouseCapture 
> jquery-ui-1.8.24.min.js:23a.widget._mouseDown 
> jquery-ui-1.8.24.min.js:23(anonymous function) 
> jquery-ui-1.8.24.min.js:23p.event.dispatch 
> jquery-1.8.2.min.js:19g.handle.h jquery-1.8.2.min.js:19 

代碼

Javascript代碼執行駐留我ViewPresentationSchedule.cshtml頁面,該頁面返回的View上:

<script type="text/javascript"> 
    function showAddForm() { 
     $('#AddPresenterForm').load('@Url.Action("AddPresenterForm", "Pod", new { podId = pod.PodId })', 
      function() { 
       showform(); 
      } 
     ); 
    } 

    //fades in our help popup and makes it draggable but not resizable 
    function showform() { 
     var windowWidth = document.documentElement.clientWidth; 
     var windowHeight = document.documentElement.clientHeight; 
     var popupHeight = $('#AddPresenterForm').height(); 
     var popupWidth = $('#AddPresenterForm').width(); 
     $('#AddPresenterForm').css('position', 'absolute'); 
     $('#AddPresenterForm').css('top', windowHeight/2 - popupHeight/2); 
     $('#AddPresenterForm').css('left', windowWidth/2 - popupWidth/2); 
     $('#AddPresenterForm').fadeIn('slow', 
     function() { 
      $('#AddPresenterForm').draggable(); 
      $('#AddPresenterForm').css('display', 'block'); 
     }); 
    } 

</script> 

股利上ViewPresentationSchedule .cshtml,它返回一個View

<div id="AddPresenterForm"> 

</div> 

鏈接促使所有魔術發生:

<a href="#" onclick="showAddForm()">Add Presenter</a> 

任何想法可能會發生?我懷疑jQuery UI沒有正確加載/初始化,因爲我在其他頁面上執行了.datepicker()命令也不行。

+0

'showform()'函數的哪一行會拋出錯誤? – 2014-09-06 08:22:28

+0

@StephenMuecke它實際上處理成功。這是當我點擊DIV拖動它,我遇到了錯誤。 – RavB 2014-09-06 22:02:16

+1

檢查瀏覽器的調試器控制檯是否有網絡錯誤。根據我的經驗,該錯誤意味着腳本沒有正確下載,或腳本以錯誤的順序執行。 – 2014-09-10 17:58:29

回答

1

經過進一步調查,有什麼問題我的jQuery的文件。我刪除它們並從CDN中檢索它們,現在一切正常。

0

也許它與你初始化的地方draggable()有關。在加載內容之前,您可能需要初始化draggable()。我假設#AddPresenterForm處於隱藏狀態,直到單擊添加演示者按鈕,在這種情況下,如果它已變爲可見狀態時它已經可以拖動就不會出現問題。

如果這似乎不起作用,你可以使用jQuery UI模式對話框,它可以使你的工作變得更容易。

下面是這似乎符合你正在嘗試做一個例子的鏈接:http://jqueryui.com/dialog/#modal-form