Home > Web Front-end > JS Tutorial > body text

jquery operates checkbox to select all and deselect all_jquery

WBOY
Release: 2016-05-16 16:50:30
Original
1055 people have browsed it

Today I wrote a function to select all and cancel all:

Select all: $(":checkbox").attr("checked","checked");

Cancel all Select: $(":checkbox").removeAttr("checked");

Get selected: $(":checked[checked='checked']")

Discover all points You can select it. You can also click to cancel the selection of all. The selected one will be invalidated. Clicking any button next time will have no effect.

This doesn’t work. I don’t know why. This is a problem with scripting languages. It was flexible and weird at the same time, and I didn’t look for the reason. Later I changed it to this:

Select all: $(":checkbox").prop("checked",true)

Cancel all Select: $(":checkbox").prop("checked",false)

Get checked: $(":checkbox:checked")

Invert selection:

Copy code The code is as follows:

$(":checkbox").each(function(){
if($(this).prop("checked")){
$(this).prop("checked",false);
}else{
$(this).prop("checked ",true);
}
});
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template