jquery - 如何使 jQuery 对话框仅在单击按钮后才显示?

标签 jquery dialog

此代码来自 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 -->

谁能告诉我如何在我按下按钮后才能制作这个节目?现在,它在加载后立即自动显示在页面中。

最佳答案

在页面中添加按钮,并在按钮的点击事件中添加代码。

<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"/>

关于jquery - 如何使 jQuery 对话框仅在单击按钮后才显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1413147/

相关文章:

jquery - Metro UI CSS - 下拉菜单不起作用

jquery - 当使用 jQuery 的 getScript() 函数时,我在带有注释的行上收到 "not well-formed"错误

android - 当我在它外面点击时,我的应用程序内结算对话框消失了

android - 对话框 fragment 中的自动完成 TextView 显示 Android 中的建议

Reactjs Material UI 如何为对话框组件设置较低的 z-index

javascript - 使用 wp_enqueue_script() 在 Wordpress -functions.php 中添加 Javascript

javascript - 在 jQuery 中,我应该选择 live()、delegate() 还是 on()?

javascript - JQuery 两次调用 Controller (MVC)中的方法

android - 如何更改 alertDialog 中的单选按钮样式

android 游戏暂停屏幕、对话框或 Activity 对话框?