2011-02-03 4 views
0

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

今、私が持っている:

confirmDialogがある
// 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; 
}); 

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; 
}); 

あなたが提供できるガイダンスは大変ありがとう!

答えて

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; 
}); 

をそして、あなたはキャンセルに何をすべきかを言うために別の変数を追加することによって、これを拡張することができます。

+0

これを初めて投稿したときにタイプミスをしましたが、confirmDialog関数のセレクタはキャンセルボタン用でした。私はそれを修正しました。 –

+0

私はあなたに非常に巨大なビール1杯ありがとう。基本的には、コールバック関数を作成しました。ところで、 '$(this).parent() 'を呼び出すと、元のリスト項目の代わりにモーダルボックスを呼び出すことになるので、セレクタのキャッシュが終了しました。 – iwasrobbed

+0

@iWasRobbed:そうです、それは基本的に私がやったことです。そして、ごめんなさい。私はちょうど元のクリック機能から新しいものに動作をコピーしました。私は完全性のために編集します。 **編集**固定! –

-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; 
}); 
+0

申し訳ありませんが、それは動作しません。 – iwasrobbed

+0

@ user341652: 'confirmDialog'はa)' confirm() '関数と同じではなく、b)関数はモーダルではないポップアップを作成するので、これは動作しません呼び出し関数にtrueまたはfalseを正しく返すことができます。 –