0

私の問題は、確認を実行しているページに動的に適用された要素に関連しています。コードは要素を正しくターゲットにして確認部分を尋ねますが、問題は、[はい] を選択した場合です。戻り値がどこに隠されているのかわかりません。以下の私の考えのようにクラスに設定されておらず、値も返されません。ある種の。

削除したい要素の確認から何らかの形式の戻り値を取得する方法を知っている人はいますか?

    $('.deleteMe').live('click', function() {

        confirmFunction(this);
        if ($(this).hasClass('confirm')){ alert("yea");} else {alert("no");}
    });

    function confirmFunction(element) {
        $(element).confirm({
          msg:'Confirm Action!<br />',
          stopAfter:'ok',
          eventType:'click',
          timeout:5000,
          buttons: { ok:'Yes', cancel:'No', separator:' - '}
        });
    }
4

1 に答える 1

1

プラグインページの例を理解すると、次のようになります。

確認が成功した場合に実行するクリックハンドラーを割り当ててから、確認プラグインを割り当てます。

 $('.deleteMe').live('click',function() {
    // Code here for when they click YES on the confirm box.
    // This only executes in 2 scenarios, either the item was clicked
    //   and the confirm plugin was not active, or it was active and
    //   the user selected Yes.
 });

 function updateConfirms() {
    $('.deleteMe').confirm({
      msg:'Confirm Action!<br />',
      stopAfter:'ok',
      eventType:'click',
      timeout:5000,
      buttons: { ok:'Yes', cancel:'No', separator:' - '}
    });
 }

 updateConfirms();

前述の動的な性質により、確認が必要な新しい要素を追加した後、updateConfirms()を呼び出す必要があります。

編集:Liveを使用せず、追加後にクリックハンドラーと確認を更新してみましょう。

 function updateConfirms() {
   $('.deleteMe').click(function() {
    // Code here for when they click YES on the confirm box.
    // This only executes in 2 scenarios, either the item was clicked
    //   and the confirm plugin was not active, or it was active and
    //   the user selected Yes.
   });

   $('.deleteMe').confirm({
     msg:'Confirm Action!<br />',
     stopAfter:'ok',
     eventType:'click',
     timeout:5000,
     buttons: { ok:'Yes', cancel:'No', separator:' - '}
   });
 }

 updateConfirms();
于 2011-06-07T20:20:42.167 に答える