How to select and invert all checkboxes in js

一个新手
Release: 2017-09-30 09:04:38
Original
2221 people have browsed it

This article is about check boxes, which have two forms: 1. Select all and inverse selection are implemented by 2 buttons; 2. Select all and inverse selection are implemented by one button.


   复选框demo   

全选 反选 苹果 香蕉 梨子 桃子 西瓜


全选 老子 尚书 周易 诗经 孟子 中庸

Copy after login

I encountered a problem in practice - check fails to select all. The solution is to use prop method instead of attr.


$("input[name='book']").attr("checked", "checked"); $("input[name='book']").prop("checked", "checked");
Copy after login

This may be related to the jQuery version.

The above is the detailed content of How to select and invert all checkboxes in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!