Jquery 如何使整个li元素可单击以切换复选标记?(引导程序4)
我有一个列表,其中每一行在左边有名字,在右边有一个复选标记,我希望能够只点击整个元素来切换复选框,无论是javascript还是htmlJquery 如何使整个li元素可单击以切换复选标记?(引导程序4),jquery,list,checkbox,bootstrap-4,Jquery,List,Checkbox,Bootstrap 4,我有一个列表,其中每一行在左边有名字,在右边有一个复选标记,我希望能够只点击整个元素来切换复选框,无论是javascript还是html <li href="#" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center"> <span><img class="menu-icon" src="icon.png">Me
<li href="#" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
<span><img class="menu-icon" src="icon.png">Menu 1</span>
<label class="checkbox my-auto">
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
</li>
菜单1
您可以在li标记上设置事件侦听器,以便在单击时切换复选框
$(document).ready(function() {
$('.list-group-item').on('click', function() {
let checkbox = $(this).find('input');
if (li.prop('checked') == true)
li.prop('checked', false);
else
li.prop('checked', true);
});
}