2013-02-23 230 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