[英]How to get count of checkbox checked which has same value in next td textbox dynamically created td?
在这里我可以同时选择多个复选框和复选框下一个td值可能有重复。 如果选中复选框,则td值具有相同的值两次需要计数为2,依此类推。
我的桌子
echo '<tr style = "text-align:left"><td><input type = "checkbox" class = "selected_id_v" name = "selectd_prcs[]" value = '.$value->labdetail.'></td><td>'.$value->id.'</td></tr>
我试过的
$(document).on('change','.selected_id_v',function () {
if($(this).is(':checked'))
{
var parseInt(checked_val) = $(this).parent().parent().children().eq(1).text();
}
});
您可以使用属性equals选择器
$(document).on('change', '.selected_id_v', function() { if (this.checked) { var checked_val = $(this).val(); var $els = $('.selected_id_v[value="' + checked_val + '"]:checked'); var count = $els.length; console.log(checked_val + ':' + count) } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr style="text-align:left"> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='1'> </td> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='2'> </td> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='3'> </td> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='3'> </td> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='2'> </td> <td> <input type="checkbox" class="selected_id_v" name="selectd_prcs[]" value='2'> </td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.