The example of this article analyzes the checkbox selection problem based on jQuery. Share it with everyone for your reference, the details are as follows:
I encountered a very strange problem recently when developing a project, that is, whether to select all or not select all in the checkbox
Using the jQuery framework. I have always used
//检测选中的checkbox $('input[name="abc"]:checked').each(function(){})
However, I found that when I need to select all, I use
$('input[name="abc"]').attr('checked',true); $('input[name="abc"]').attr('checked',false);
. It works when loading for the first time. Clicking it again will only show itself
But when I click When I checked the source code, I found that the checked attribute had been added. I was puzzled. Finally, I found out that it was the attr attribute. For checked, it would not change the dom style, but would only change its attribute value. jquery provided The alternative method is as follows
$('input[name="abc"]').prop('checked',true); $('input[name="abc"]').prop('checked',false);However, the problem comes again. When not selecting all, I can’t detect which element is clicked, and then I make a fuss about the name
$('input[name="abc[]:checked"').each(function(i){}); //或者 $('input[name="abc[]"').each(function(i){ var flag = $(this).prop('checked'); if(flag){ //$(this) 即为选中元素 } })problem solved.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
