2016-11-04 5 views
0

私がしたいのは、チェックボックスを使ってチェックされた特定の行の背景色を変更することです。問題は、最初の行だけを選択(色付け)できることです。あなたはイベントのために間違った選択を持っているjqueryで複数行のチェックボックス

PHP

<td align=center> 
<input value='.$row['id'].' type=checkbox name=flag id=flag '.$tick.'> 
</td> 

jqueryの

$("#flag").on('change', function() { 
    var matching = $(this).closest('tr') 
    if($(this).prop('checked') == true) { 
     matching.css({'background-color':'rgba(175,0,0,0.2)'}); 
    } 
    else { 
     matching.css({'background-color':'rgba(175,0,0,0)'}); 
    } 
}); 

答えて

2

、試してみてください。

$("input[name='flag']").on('change', function() { 
    var matching = $(this).closest('tr'); 
    if($(this).is(':checked')) { 
     matching.css({'background-color':'rgba(175,0,0,0.2)'}); 
    } 
    else { 
     matching.css({'background-color':'rgba(175,0,0,0)'}); 
    } 
}); 
関連する問題