我使用jQuery和Ajax刪除橫幅圖像。只有當我的圖像列表中有多個圖像時才顯示我的鏈接「刪除」
但是,如果我只有一個圖像,我不想刪除它。
我有圖像的列表,併爲每個圖像我有此鏈接:
echo '<a class="delete j_bannerdelete" id="'.$rslt_banner['id'].'" href="#">Delete</a> ';
我想講講tihs,只是顯示「刪除」鏈接,如果我的行數超過1。
if($read_ban->rowCOunt() >1{
echo '<a class="delete j_bannerdelete" id="'.$rslt_banner['id'].'" href="#">Delete</a> ';
}
但是像這樣,例如,如果我有2個圖像,我刪除一個,並作爲即時通訊與阿賈克斯刪除,我的網頁不刷新,所以我有我的最後一個影像與我的「刪除」鏈接,所以我可以刪除它。
你知道一個簡單的方法來解決這個問題嗎?
我刪除代碼:
$(function(){
var banner_id = null;
$("a#no").click(function(event){
event.preventDefault();
$('.confirm').fadeOut("slow",function(){
$('.delete_dialog').fadeOut("slow");
});
$('.bannerli li[id="'+ banner_id +'"]').css('background','#f5f5f5');
banner_id = null;
});
$("a#delete").click(function(event){
event.preventDefault();
if (!banner_id) return;
$.post(url,{action:'ban',id: banner_id},function(){
window.setTimeout(function(){
$('.bannerli li[id="'+ banner_id +'"]').fadeOut("slow");
},500);
$('.confirm').fadeOut("fast",function(){
$('.delete_dialog').fadeOut("fast");
});
});
});
$('.bannerli').on('click','.j_bannerdelete',function(){
banner_id = $(this).attr('id');
$('.bannerli li[id="'+ banner_id +'"]').css('background','red');
$('.delete_dialog p').text('Are you sure you want to remove this banner?');
$('.delete_dialog').fadeIn("slow",function(){
$('.confirm').fadeIn("slow");
});
return false;
})
});
感謝您的解決方案。但我更簡單地使用它,它似乎是正常工作。我在我的文檔reay這個調用disableDeleteIfOnlyOneItem(1);當我刪除我的圖像後,我有這個調用disableDeleteIfOnlyOneItem(2);我只是使用你的函數:function disableDeleteIfOnlyOneItem($ value)if($('。bannerli li')。length'= $ value){('。j_bannerdelete')。hide(); } }看起來一切正常!謝謝! – OzzC 2014-08-29 20:56:55