2011-06-07 89 views
0

我的問題是關於動態應用的元素到我正在運行確認的頁面。代碼正確地定位元素並詢問確認部分,但問題是如果選擇「是」,我不知道隱藏了返回值的位置,它不是像下面的我的想法那樣在類中設置,也不返回值各種各樣的。JQUERY LIVE確認問題

任何人都知道如何從確認我想刪除的元素獲得某種形式的返回值?

$('.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:' - '} 
     }); 
    } 

回答

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

嗨,我已經嘗試似乎已不幸的是說什麼也不會刪除方法鏈接。我添加了被調用的元素,然後按照您的指示運行該函數,但似乎並未將確認處理程序添加到.deleteMe元素。只要我點擊deleteMe元素,它就直接進入警報hello call而不是確認。 – John 2011-06-07 20:26:53

+0

@John好吧,也許這是導致問題的'生活'部分。我會發佈一個快速修改。 – Fosco 2011-06-07 20:29:49

+0

好男人欣賞:) – John 2011-06-07 20:30:33