2014-10-18 66 views
0

我想創建乳寧我的頁面時,一個jQuery的對話框動態模態的,但我不能讓它模式,我得到一個無模式對話框創建jQuery的模態對話框動態

那是我的簡單的代碼

 <script> 
      function show() { 
       var dialog = $('<div id="msg_dialog"></div>').dialog(); 
       dialog.dialog({ 
        modal: true, 
        autoOpen: true, 
        title: 'Test', 
        buttons: [ 
         { 
          text: 'Ok', 
          click: function() { 
           $('#res').empty().append('<h1>Open<h1>'); 
           $('#msg_dialog').remove(); 
          } 
         }, 
         { 
          text: 'Cancel', 
          click: function() { 
           $('#res').empty().append('<h1>Close<h1>'); 
           $('#msg_dialog').remove(); 
          } 
         } 
        ] 
       }); 
      } 
     </script> 

回答

0

負載模式負載 請確保您在負載上運行該功能。 試試這個代碼: 與

<body onload="show();"> 

更換<body>要不然,你可以加入這一行

window.onload = function(){show();}; 

SIMPLE MODAL代碼,以幫助你改正你的代碼

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

來源: http://jsfiddle.net/db5SX/

+0

我有它像

Zouhair 2014-10-18 13:05:10

+0

@Zouhair參見更新回答,您的代碼加載模態的onclick。 如果你提供一個jsfiddle,你的問題將會很容易理解。 – Avadhesh18 2014-10-18 13:08:50

+0

thx Avadhesh18,我無法得到一個模態對話框,我得到一個沒有模態對話框,issu,我怎麼能得到一個**模態**對話框動態 – Zouhair 2014-10-18 13:13:00