2013-02-23 168 views
1

即時得到來自DATABSE數據,依賴於得到想要的結果記錄,但IM數格的數量,如果我點擊第四按鈕第一個div被刪除,但我希望它首先刪除第四格不,我的代碼是在這裏刪除點擊按鈕,按鈕的div點擊

<button class="mws-button red" type="button" id="red_remove_<?php echo $i;?>"onclick="rem(id,id);">Remove</button> 

我已經呼籲按鈕此功能點擊

var count=0; 
function rem(key,l){ 
$('#remove_more_opertaion'+count).remove(); 
$('#label'+count).remove(); 
count++; 
} 
+0

開始計數在'$(「[id^= remove_move_operation]」).length'並使用'count - '代替 – 2013-02-23 07:21:13

回答

0

使用分割功能和搭配的數量和刪除點擊的按鈕格

2

氯eaner辦法做到這一點使用jQuery:

HTML:

<button class="mws-button red remove-btn" 
     type="button" 
     data-id="<?php echo $i; ?>" // <-- will use this id to remove corresponding div 
     id="red_remove_<?php echo $i;?>">Remove</button> 

JS:

$('.remove-btn').click(function() { 
    var id = $(this).data('id'); 
    $('#remove_more_opertaion' + id).remove(); 
    $('#label' + id).remove(); 
}); 

阿洛斯沒有必要使用onclick="..."因爲你有jQuery的。

+1

很好的使用數據屬性 – 2013-02-23 07:23:45

+1

很好的邏輯去除div – Shahbaz 2013-02-23 08:19:00