天天看点

onclick监听事件点击一次触发多次问题

解决方法:加off解除委托的事件
$('.producttable tbody').on('click','tr',function(){
   if ($(this).hasClass('rchecked')){
      $(this).removeClass(
         'rchecked').find('input').prop('checked',
         false);       
   } else {
      $(this).closest('tbody').find('tr').not($(this).index()).removeClass('rchecked');
      $(this).addClass('rchecked').find('input').prop("checked",
         true);
   }
   
})

$('.producttable tbody').off('click','tr').on('click','tr',function(){
    //debugger
    //alert('产品点击事件')
   if ($(this).hasClass('rchecked')){
      $(this).removeClass(
         'rchecked').find('input').prop('checked',
         false);       
   } else {
      $(this).closest('tbody').find('tr').not($(this).index()).removeClass('rchecked');
      $(this).addClass('rchecked').find('input').prop("checked",
         true);
   }

  
})