2011-05-04 109 views
0

我有2個簡單的頁面。jquery對話框關閉不起作用

索引包含一個帶有錨定標記的超鏈接,它使用jquery的函數單擊定義。 該頁面還包含一個名爲「容器」

單擊功能使用.dialog()

對話頁面本身是在我嘗試關閉該對話框第二頁打開dailog DIV但這並不工作。

你能解釋一下爲什麼這不起作用嗎?

======代碼INDEX PAGE ===========

<script type="text/javascript"> 
    $().ready(function() { 
     $("#LaunchModal").click(function() { 
      $.get(
       "Home/RandomPopupView", 
       function (htmlResult) { 
        $("#RandomModal").remove(); //In case this is the second time they've requested the dialog. 
        $("#container").append(htmlResult); 
        $("#RandomModal").dialog(); 
       } 
      ); 
      return false; //To keep the default behavior of the anchor tag from occuring. 
     }); 
    }); 
</script> 
<a href="" id="LaunchModal">Launch Modal!</a> 
<div id="container"> 

======代碼對話頁面==== =======

<div id="RandomModal"> 
    <script type="text/javascript"> 
     $().ready(function() { 

      //TEST TRY TO CLOSE THE DIALOG DIV IMMEDIATELY FROM WITHINN THE DIV ITSELF 
      $("#RandomModal").dialog("close"); //CLOSE DOES NOT WORK 

      $("#submitModal").click(function() { 
       var SomeString = $("#SomeString").val() 

       $.post("/Home/RandomPopupViewPOST", 
       { 
        SomeString: SomeString 
       }, 
        function (html) { 
         $("#RandomModal").empty(); 
         $("#RandomModal").append(html); 
        }); 
      }); 
     }); 
    </script> 
</div> 

==================================== ===

回答

1

get方法不加載頁面,你就需要加載iframe來第二頁上的準備事件來觸發

所以我想我們把你的代碼在主要頁面,並使用現場活動

$("#submitModal").live("click",function() { 
    var SomeString = $("#SomeString").val() 

    $.post("/Home/RandomPopupViewPOST", 
    { 
     SomeString: SomeString 
    }, 
     function (html) { 
      $("#RandomModal").empty(); 
      $("#RandomModal").append(html); 
     }); 
}); 

,雖然我不知道這就是正確的解決方案要麼我看了你的代碼,我越不明白你要做

0

$("#RandomModal").dialog("close");代碼保留在索引頁上。

1

如果要加載和執行其他腳本的越多,你應該使用$.getScript()

請參閱jQuery網站上的文檔以更好地瞭解如何使用它:jQuery.getScript()