2011-09-09 64 views
1

第一個函數(可在http://nadiana.com/jquery-confirm-plugin找到):如何結合兩個jQuery函數?

$('#confirm').confirm(
{ 
    msg: 'You are about to delete gallery and all images related to that gallery. Are you sure?<br>', 
    buttons: { 
    separator: ' - ' 
    } 
} 
); 

基本上沒有是/否的問題,如果你回答是,它進一步進行。

二級功能:

$(document).ready(function() { 
    $('#load').hide(); 
}); 
$(function() { 
    $(".delete").click(function() { 
     $('#load').fadeIn(); 
     var commentContainer = $(this).parent(); 
     var id = $(this).attr("id");    
     var string = 'id='+ id ; 

     $.ajax({ 
      url: "<?php echo site_url('gallery/delete_image') ?>", 
      type: "POST", 
      data: string, 
      cache: false, 
      success: function(){ 
       commentContainer.slideUp('slow', function() {$(this).remove();}); 
       $('#load').fadeOut(); 
      } 
     }); 
     return false; 
    }); 
}); 

此功能用於刪除圖像。 我如何結合這兩個功能?首先,我想問問題,如果單擊是繼續刪除。

+0

當有人說我愛「舒爾」:d – genesis

+1

'$(文件)。就緒(函數(){'和'$(函數(){'實際上是一回事 – Blazemonger

+0

@genesis:!我愛fainthful Linux的傢伙')' –

回答

2

根據您聯繫,您只需使用爲您的動作相同的選擇和您的確認文件:

$(document).ready(function() { 
    $('#load').hide(); 

    $(".delete").click(function() { 
     $('#load').fadeIn(); 
     var commentContainer = $(this).parent(); 
     var id = $(this).attr("id");    
     var string = 'id='+ id ; 

     $.ajax({ 
      url: "<?php echo site_url('gallery/delete_image') ?>", 
      type: "POST", 
      data: string, 
      cache: false, 
      success: function(){ 
       commentContainer.slideUp('slow', function() {$(this).remove();}); 
       $('#load').fadeOut(); 
      } 
     }); 
     return false; 
    }); 



    $('.delete').confirm(
    { 
     msg: 'You are about to delete gallery and all images related to that gallery. Are you sure?<br>', 
     buttons: { 
     separator: ' - ' 
     } 
    }); 
}); 
+0

沒有看到來了: D.謝謝你幫助我。 – Sasha

0

它更是關係到你選擇的插件問題,但你可以在插件它只是將兩個事件相同的元素和插件沒有休息的手冊中讀出。

從網站:

簡單地說,這樣可以節省綁定到元素的所有事件處理程序的副本,他們解除綁定並結合本身,而不是。用戶觸發該操作時會顯示一個確認對話框。如果用戶選擇用動作來進行,它再次重新綁定的處理程序和觸發事件。如果用戶選擇取消操作,對話框將消失。

所以,你需要做的是一樣的東西:

$('#delete').click(function(){ ... }); 
$('#delete').confirm(); 

當然你也可以在需要擴展這個。