2013-07-29 47 views
6

我有一個jQuery對話框。我在對話框中顯示一個asp.net gridview。 我想根據網格視圖的大小來改變對話框的大小。動態更改jQuery UI對話框的大小

有一個按鈕,當點擊它時會顯示對話框。

我想設置對話框的大小,使gridview完全適合它。

I have my javascript code below : 



$("#ViewModalPopup").dialog({ 
       height: 800px, 
       scrollable: true, 
       width: 800, 
       modal: true 

      }); 

這裏#ViewModalPopup是包含模式彈出窗口的div。

我試圖實現下面的邏輯來調整對話的基礎上,div的尺寸高度:

var maxHeight = 600; 
      var currentHeight = $('#ViewModalPopup').height(); 

if (currentHeight < maxHeight) { 
       var desiredHeight = currentHeight 
       } 
      else 
      { 
       var desiredHeight = maxHeight; 
       } 

    $("#ViewModalPopup").dialog({ 
        height: desiredheight, 
        scrollable: true, 
        width: 800, 
        modal: true 

       }); 

但它不工作作爲

var currentHeight = $('#ViewModalPopup').height(); 

是走出來是從第二個按鈕點擊向下空。

有什麼辦法可以動態地改變對話框的大小嗎?

+0

當你沒有設置高度在所有會發生什麼? –

+0

嗨Jason P!有時gridview有很多行,從屏幕的頂部延伸到底部。設置高度並放置滾動條有助於限制對話框的高度。 – CodeNinja

+0

所以你基本上想要一個最大高度。你有沒有嘗試使用css在對話框div上設置'max-height'? –

回答

7

設置像

$("#ViewModalPopupDiv1").dialog("option", "maxHeight", 600); 

API

+0

嘿,謝謝! $(「#ViewModalPopupDiv1」)。dialog(「option」,「maxHeight」,600);實際上我正在尋找。感謝您指點我正確的方向。 – CodeNinja

+1

*** maxheight ***而不是***身高***? – Kiquenet

相關問題