0

Faceboxダイアログでキャンセルまたは削除ボタンが押されたかどうかを確認するjQuery関数を作成しようとしていますが、どうすればよいかわかりません。

今、私は持っています:

// Confirm and remove group members
$("[id^='removeGroupMember_']").click(function () {
        confirmDialog('Removal', 'Are you sure you want to remove this person from the group?');

        //  I need to check the results of the confirm dialog prior
        //  to calling the code below to remove the actual rows

        $(this).parent().slideUp("fast", function () {
            $(this).remove();
            updateGroupRows();
        });
    return false;
});

どこconfirmDialogにある:

function confirmDialog(action, message) {
    $.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>');
};

現在、これらのボタンが押されたときの関数が 2 つありますが、関連する行を削除するかどうかを決定できるように、結果を確認してフィードバックする方法がわかりません。

$('#dialogConfirmAction').live('click', function() {
    console.log('Yep... they dun clicked it.');
    return true;
});

$('#dialogConfirmCancel').live('click', function() {
    $.facebox.close();
    return true;
});

あなたが提供できるガイダンスは大歓迎です!

4

2 に答える 2

1

やりたいことは、confirmDialog関数を次のように変更することです。

function confirmDialog(action, message, actionfunc) {
    $.facebox('<h3 class="confirmHeader light tb">Confirm ' + action + '</h3><div class="confirmContent"><p>' + message + '</p><a href="#" id="dialogConfirmAction" class="ras small red button right">' + action + '</a><a href="#" id="dialogConfirmCancel" class="ras small gray button right">Cancel</a></div>');
    if(actionfunc) {
        $('#dialogConfirmAction').click(actionfunc);
    }
};

次に、関数に関数を渡すことで、「アクションで」発生させたいことを渡すことができconfirmDialogます。これにより、他のコードは次のようになります。

$("[id^='removeGroupMember_']").click(function () {
    var $that = $(this);
    confirmDialog('Removal', 'Are you sure you want to remove this person from the group?',
                  function() {
                      //This function will be run when the "action" link is clicked
                      $that.parent().slideUp("fast", function () {
                          $(this).remove();
                          updateGroupRows();
                      });
                  });
    return false;
});

また、別の変数を追加して、キャンセル時に何をするかを指定することで、これを拡張できます。

于 2011-02-03T22:00:09.323 に答える
-1

これを試して:

 // Confirm and remove group members
$("[id^='removeGroupMember_']").click(function () {

        if(confirmDialog('Removal', 'Are you sure you want to remove this person from the group?')) {
            //  I need to check the results of the confirm dialog prior
            //  to calling the code below to remove the actual rows

            $(this).parent().slideUp("fast", function () {
                $(this).remove();
                updateGroupRows();
            });
        }
    return false;
});
于 2011-02-03T21:06:44.227 に答える