2013-07-22 64 views
0

這是執行刪除操作的代碼。出現四個圖像,但通過提供onload功能不會顯示刪除操作的警報框。請指導我...這裏是代碼。使用javascript刪除操作,但此代碼不起作用

// script for deletedelete operation 

    $(document).ready(function(){ 

     $('a.delete').on('click',function(e){ 
      e.preventDefault(); 
      imageID = $(this).closest('.image')[0].id; 
      alert('Now deleting "'+imageID+'"'); 
      $(this).closest('.image') 
       .fadeTo(300,0,function(){ 
        $(this) 
         .animate({width:0},200,function(){ 
          $(this) 
           .remove(); 
         }); 
       }); 
     }); 

    }); 

HTML

//four images being given with delete link 


<div id="container"> 
     <div class="image" id="image1" style="background-image:url(http://lorempixel.com/100/100/abstract);"> 
      <a href="#" class="delete">Delete</a> 
     </div> 
     <div class="image" id="image2" style="background-image:url(http://lorempixel.com/100/100/food);"> 
      <a href="#" class="delete">Delete</a> 
     </div> 
     <div class="image" id="image3" style="background-image:url(http://lorempixel.com/100/100/people);"> 
      <a href="#" class="delete">Delete</a> 
     </div> 
     <div class="image" id="image4" style="background-image:url(http://lorempixel.com/100/100/technics);"> 
      <a href="#" class="delete">Delete</a> 
     </div> 
    </div> 
+0

刪除當我點擊每個刪除鏈接。你的問題是什麼? –

+0

Works fine [here](http://jsfiddle.net/A5u43/24/) –

+0

yes即使我嘗試了它的完美工作http://jsfiddle.net/vinodlouis/rJ5nw/ –

回答

0

一切工作確定....讓我帶一個在這裏拍攝。你可能沒有在你的代碼中包含Jquery文件?

您有加入此標記

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 

FIDDLE只是你的代碼拷貝粘貼。沒有一個變化

HTML

<div id="container"> 
    <div class="image" id="image1" style="background-image:url(http://lorempixel.com/100/100/abstract);"> 
     <a href="#" class="delete">Delete</a> 
    </div> 
    <div class="image" id="image2" style="background-image:url(http://lorempixel.com/100/100/food);"> 
     <a href="#" class="delete">Delete</a> 
    </div> 
    <div class="image" id="image3" style="background-image:url(http://lorempixel.com/100/100/people);"> 
     <a href="#" class="delete">Delete</a> 
    </div> 
    <div class="image" id="image4" style="background-image:url(http://lorempixel.com/100/100/technics);"> 
     <a href="#" class="delete">Delete</a> 
    </div> 
</div> 

JQUERY

$('a.delete').on('click',function(e){ 
     e.preventDefault(); 
     imageID = $(this).closest('.image')[0].id; 
     alert('Now deleting "'+imageID+'"'); 
     $(this).closest('.image') 
      .fadeTo(300,0,function(){ 
       $(this) 
        .animate({width:0},200,function(){ 
         $(this) 
          .remove(); 
        }); 
      }); 
    }); 
+0

它的全部完成......但我不知道...它不工作4我!! !! – Rohini

+0

你試過小提琴嗎?它只是你的代碼。你試過其他機器嗎? – AnaMaria

+0

試試這個方法。其驚人的https://en.wikipedia.org/wiki/Rubber_duck_debugging – AnaMaria

0

的代碼是工作的罰款......如果你不包括jQuery的文件,包括它..

<腳本src =「http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js」>

</SCRIPT>

<腳本> $(文件)。就緒(函數(){

$('a.delete').on('click',function(e){ 
    e.preventDefault(); 
    imageID = $(this).closest('.image')[0].id; 
    alert('Now deleting "'+imageID+'"'); 
    $(this).closest('.image') 
     .fadeTo(300,0,function(){ 
      $(this) 
       .animate({width:0},200,function(){ 
        $(this) 
         .remove(); 
       }); 
     }); 
}); 

});

</script>

+0

您的回答沒有添加任何新內容。對不起,因爲是殘酷的誠實,但在SO,這些是規則。 – AnaMaria

+0

我剛剛重新啓動我的瀏覽器,並試圖...謝謝它現在工作正常!!!!相同的代碼..... – Rohini

+0

我想這個代碼在t上我添加的縮略圖。我以縮略圖的形式將圖像添加到我的畫廊,並且希望也包含刪除操作。此代碼不起作用。幫我解決...... //渲染縮略圖。 var span = document.createElement('span'); span.innerHTML = ['Delete'] .join(''); – Rohini