如何打开一个对话框窗口

jQuery: how to open a dialog window

本文关键字:一个 对话框 窗口 何打开      更新时间:2023-09-26

我有一个按钮在我的网页;我的期望是当我点击按钮时,它会弹出一个对话窗口;在对话框窗口,它有是/否按钮;如果我点击yes,它会打开一个新页面(由php生成);如果我点击no,我就会回到原来的页面。我该怎么做呢?

<input type="button" name="terminate" value="terminate" id="terminate" title="Terminate"  onclick="terminateIt();"/>

有无数的方法可以做到这一点。

也许最常见的方法是使用jQuery UI的对话框。

他们在演示中有一个带有两个按钮的对话框的例子。下面是该演示的一个片段:

HTML:

<div id="dialog-confirm" title="Empty the recycle bin?">
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Your question goes here. Are you sure?</p>
</div>

JS:

    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            Yes: function() {
                window.open(....);
                $( this ).dialog( "close" );
            },
            No: function() {
                $( this ).dialog( "close" );
            }
        }
    });

查看整个jQuery UI库。很多很棒的东西让做一些基本的事情变得很容易。

function terminateIt(){
    var r = confirm("Go to new page?");
    if( r == true ){
        // redirect stuff here
    } else {
        // non redirect stuff here 
    }  
}