2012-07-14 3 views
1

누군가 제발 나를 도울 수 있는지 궁금합니다.jQuery Image 삭제 확인 메시지

첫 번째로, 저는 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이 각 이미지의 맨 아래에 사라졌습니다.

나는 자바 스크립트 콘솔에 들어갔다. 그 내용은 다음과 같다 : 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에 테스트 사례를 추가 할 수 있으면 언제든지 가능합니까? –

+0

안녕하세요, @kennis, 내 게시물에 회신하는 시간을내어 주셔서 감사합니다. 원래 게시물에 테스트 페이지 링크를 추가했습니다. 감사합니다 – IRHM

답변

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

성공 함수가 없습니다. data 매개 변수

+0

안녕하세요, @ user1042031, 정말 고마워요. 이렇게하면 '갤러리'형식과 '휴지통'아이콘이 다시 표시되지만 아이콘을 클릭해도 아무런 변화가 없습니다. 아마도'$ .ajax' 함수가 클릭 이벤트를 처리 할 것이라고 잘못 생각한 것 같습니다. 좋은 점은 – IRHM

+0

좋아, 이제 삭제 확인을 볼 수 있니? 내 anwser에서 아약스 성공 콜백 함수가 잘못되었다는 것은 성공 : function (response) {}과 같아야한다. –

+0

안녕하세요 @ user1042031, 너무 빨리 저에게 다시 연락해 주셔서 감사합니다. 불행히도 '확인 메시지'가 보이지 않습니다. 실제로 페이지를 새로 고침 할 때 동일한 문제, 즉 잘못된 갤러리 형식과 누락 된 '삭제'아이콘이 다시 발생합니다. – IRHM