相关疑难解决方法(0)

当用户按下按钮但不能正常工作时,jquery ui对话框需要返回值

我有一个jquery ui对话框我想用来提示用户确认删除.当用户按下"是"或"否"时,我需要返回"True"或"False"以继续执行一些javascript.下面的代码的问题是当对话框显示它立即执行"return true"时 但用户还没按下"是"按钮呢?

我究竟做错了什么?

HTML:

<div id="modal_confirm_yes_no" title="Confirm"></div>
Run Code Online (Sandbox Code Playgroud)

Javascript电话:

$("#modal_confirm_yes_no").html("Are you sure you want to delete this?");
var answer = $("#modal_confirm_yes_no").dialog("open");

if (answer)
{
     //delete
}
else
{
     //don't delete
}
Run Code Online (Sandbox Code Playgroud)

Jquery对话框:

$("#modal_confirm_yes_no").dialog({
                bgiframe: true,
                autoOpen: false,
                minHeight: 200,
                width: 350,
                modal: true,
                closeOnEscape: false,
                draggable: false,
                resizable: false,
                buttons: {
                        'Yes': function(){
                            $(this).dialog('close');
                            return true;
                        },
                        'No': function(){
                            $(this).dialog('close');
                            return false;
                        }
                    }
            });
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui

21
推荐指数
1
解决办法
4万
查看次数

使用JQuery UI对话框从确认对话框返回值

I am using jQuery UI dialog to display a confirmation dialog when a button is clicked. I want to return true, when OK is clicked and false otherwise.

Associating dialog open call in onClick (as given here, $dialog.dialog('open');) event does not serve the purpose. So, as a workaround, I followed an approach, which is similar to this: http://www.perfectline.co.uk/blog/unobtrusive-custom-confirmation-dialogs-with-jquery. There are two differences between this approach and mine:

  1. The example uses anchor tag and,
  2. It does not …

html javascript jquery jquery-ui

19
推荐指数
2
解决办法
8万
查看次数

标签 统计

jquery ×2

jquery-ui ×2

html ×1

javascript ×1