2012-07-14 96 views
1

我想知道是否有人能夠幫助我。jQuery圖像刪除確認信息

首先,我誠摯的道歉,因爲我不是很熟悉JavaScript,有些人可能會覺得這是一個愚蠢的職位,但任何幫助將不勝感激。

我目前在使用下面的腳本刪除圖庫圖像。

<script type="text/javascript"> 
     Galleria.ready(function() { 
      this.$('thumblink').click(); 

     $(".galleria-image").append( 
     "<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
     $(".btn-delete").live("click", function(){ 
     var img = $(this).closest(".galleria-image").find("img"); 
     $.msgbox("You are about to delete this image. It cannot be restored at a later date. Do you wish to continue?", { 
     type: "alert", 
      buttons : [ 
      {type: "submit", value: "Delete"}, 
      {type: "cancel", value: "Cancel"} 
      ] 
      }, 
      function(result) { 
      if(result) 


      // send the AJAX request 
      $.ajax({ 
      url : 'delete.php', 
      type : 'post', 
      data : { image : img.attr('src'), idnum: "VALUE", lid: "VALUE"}, 
      success : function(){ 
      img.parent().fadeOut('slow'); 
      } 
     });    
    }); 
     return false; 
    });  
}); 

</script> 

我現在已經找到更適合自己的jQuery的確認腳本here我現在想嘗試和實施。

使用本網站的script.js文件和我現有的腳本,我試圖將它們結合起來,並拿出了以下內容:

<script type="text/javascript"> 
Galleria.ready(function() { 
    this.$('thumblink').click(); 
    $(".galleria-image").append( 
    "<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
    $('.btn-delete').click(function(){ 
    var elem = $(this).closest(".galleria-image").find('.item'); 
     $.confirm({ 
      'title'  : 'Delete Confirmation', 
      'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?', 
      'buttons' : { 
       'Yes' : { 
        'class' : 'blue', 
        'action': function(){ 
         elem.slideUp(); 
           $.ajax({ 
           url : 'delete.php', 
           type : 'post', 
           data : { image : img.attr('src'), idnum: "VALUE", lid: "VALUE"}, 
           success : function(){ 
           img.parent().fadeOut('slow'); 
           } 
          }); 

        } 
       }, 
       'No' : { 
        'class' : 'gray', 
        'action': function(){} // Nothing to do in this case. You can as well omit the action property. 
       } 
       } 
       } 
      } 
     }); 

    }); 

}); 
</script> 

我遇到的問題是,雖然頁面加載,它不會以默認的Gallery圖像格式加載,而我用作視覺觸發刪除圖像的trash icon已消失在每個圖像的底部。

我已經去到JavaScript控制檯,它顯示的錯誤是:Uncaught SyntaxError: Unexpected token }突出在我的代碼的問題,這條線:$.confirm({,但我必須誠實地說我真的不知道這意味着什麼。

我已經嘗試了很多變化的代碼,試圖讓這個工作,不幸的是沒有成功。

我只是想知道是否有人可以看看這個請給我提供一些指導我要去哪裏錯了。

許多的感謝和親切的問候

工作液

<script type="text/javascript"> 
Galleria.ready(function() { 
this.$('thumblink').click(); 
$(".galleria-image").append( 
"<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
$('.btn-delete').click(function(){ 
var img = $(this).closest(".galleria-image").find('img'); 
    $.confirm({ 
     'title'  : 'Delete Confirmation', 
     'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?', 
     'buttons' : { 
      'Yes' : { 
       'class' : 'blue', 
       'action': function(){ 
        //elem.slideUp(); 
          $.ajax({ 
          url : 'delete.php', 
          type : 'post', 
          data : { image : img.attr('src'), idnum: "VALUE", lid: "VALUE"}, 
          success : function(){ 
          img.parent().fadeOut('slow'); 
          } 
         }); 

       } 
      }, 
      'No' : { 
       'class' : 'gray', 
       'action': function(){} // Nothing to do in this case. You can as well omit the action property. 
       } 
       } 
      }); 
     }); 
    }); 
    </script> 
+0

任何機會,你可以提供一個鏈接到你正在工作的網頁,或把測試用例放在jsFiddle.net上? – 2012-07-14 15:01:09

+0

嗨@kennis,感謝您花時間回覆我的帖子。我在原始文章中添加了一個鏈接到測試頁面。親切的問候 – IRHM 2012-07-14 15:15:37

回答

0

你缺少一些支撐,它不能真正解決問題,但這段代碼首先檢查,我有必要格式化大括號並讓我們知道您的發現:

Galleria.ready(function() { 
this.$('thumblink').click(); 
$(".galleria-image").append( 
"<span class='btn-delete ui-icon ui-icon-trash'></span>"); 
$('.btn-delete').click(function(){ 
var elem = $(this).closest(".galleria-image").find('.item'); 
    $.confirm({ 
     'title'  : 'Delete Confirmation', 
     'message' : 'You are about to delete this item. <br />It cannot be restored at a later time! Continue?', 
     'buttons' : { 
      'Yes' : { 
       'class' : 'blue', 
       'action': function(){ 
        elem.slideUp(); 
          $.ajax({ 
          url : 'delete.php', 
          type : 'post', 
          data : { image : img.attr('src'), idnum: "VALUE", lid: "VALUE"}, 
          success : function(){ 
          img.parent().fadeOut('slow'); 
          } 
         }); 

       } 
      }, 
      'No' : { 
       'class' : 'gray', 
       'action': function(){} // Nothing to do in this case. You can as well omit the action property. 
       } 
       } 
      }); 
     }); 
    }); 

此外您的成功callfunction缺失data參數

+0

嗨@ user1042031,非常感謝你。這帶來了'畫廊'格式和'垃圾'圖標,但不幸的是,當我點擊圖標時,什麼都沒有發生。我想,也許錯誤地認爲'$ .ajax'函數會照顧點擊事件。親切的問候 – IRHM 2012-07-14 15:27:01

+0

好吧,現在你能看到刪除確認嗎?正如我在我的anwser中說的,你的ajax成功回調函數是錯誤的,它應該像'success:function(response){}'。 – 2012-07-14 15:30:05

+0

嗨@ user1042031,謝謝你這麼快回到我身邊。不幸的是,我沒有看到「確認信息」。事實上,當我重新加載頁面時,相同的問題,即不正確的畫廊格式和丟失的'刪除'圖標已重新發生。 – IRHM 2012-07-14 15:40:14