2009-09-11 50 views
2

此代碼來自jQuery網站上的模式確認演示。只有當我點擊一個按鈕後,如何才能從jQuery顯示中創建一個對話框?

<script type="text/javascript"> 
$(function() { 
    $("#dialog").dialog({ 
     bgiframe: true, 
     resizable: false, 
     height:140, 
     modal: true, 
     overlay: { 
      backgroundColor: '#000', 
      opacity: 0.5 
     }, 
     buttons: { 
      'Yes': function() { 
       $(this).dialog('close'); 
      }, 
      'No': function() { 
       $(this).dialog('close'); 
      } 
     } 
    }); 
}); 
</script> 



<div class="demo"> 

<div id="dialog" title="Empty the recycle bin?"> 
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p> 
</div> 

<!-- Sample page content to illustrate the layering of the dialog --> 
<div class="hiddenInViewSource" style="padding:20px;"> 
    <p>Sed vel diam id libero <a href="http://example.com">rutrum convallis</a>. Donec aliquet leo vel magna. Phasellus rhoncus faucibus ante. Etiam bibendum, enim faucibus aliquet rhoncus, arcu felis ultricies neque, sit amet auctor elit eros a lectus.</p> 
    <form> 
     <input value="text input" /><br /> 
     <input type="checkbox" />checkbox<br /> 
     <input type="radio" />radio<br /> 
     <select> 
      <option>select</option> 
     </select><br /><br /> 
     <textarea>textarea</textarea><br /> 
    </form> 
</div><!-- End sample page content --> 

</div><!-- End demo --> 

<div class="demo-description"> 

<p>Confirm an action that may be destructive or important. Set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p> 

</div><!-- End demo-description --> 

任何人都可以告訴我只有當我點擊一個按鈕後才能使這個節目?現在它會在加載後自動顯示在頁面中。

回答

0

對或錯,下面是一個通用的警報樣式d ialog,我使用:

設置對話框(在文件準備好):

$("#generic-dialog").dialog({ 
    autoOpen: false, 
    buttons: { 
     Ok: function() { 
      $(this).dialog("close"); 
     } 
    } 
}); 

,打開對話框(某些事件發生後):

$("#generic-dialog") 
    .text("Status updated successfully.") 
    .dialog("option", "title", "Your Status").dialog("open"); 
2

將按鈕添加到頁面並將代碼添加到按鈕的單擊事件。

<script type="text/javascript"> 
$(function() { 
    $("#button").click(function(){ 
    $("#dialog").dialog({ 
      bgiframe: true, 
      resizable: false, 
      height:140, 
      modal: true, 
      overlay: { 
        backgroundColor: '#000', 
        opacity: 0.5 
      }, 
      buttons: { 
        'Yes': function() { 
          $(this).dialog('close'); 
        }, 
        'No': function() { 
          $(this).dialog('close'); 
        } 
      } 
     }); 
    }); 
    }); 
</script> 

,並在HTML

<input type='button' value="click" id="button"/> 
+0

我只是*秒*的速度太慢... +1,我的答案被刪除。 – 2009-09-11 20:47:31

1
$("#btnTest").click(function() { 
     $('#dialog').dialog('open'); 
     return false; 
    }) 

這應該打開您已經定義對話框 - 附加對話框打開功能點擊按鈕

哦事件 - 並在設置autoOpen: false對話框設置屬性:)

相關問題