Home > Web Front-end > JS Tutorial > jquery code to determine whether checkbox is selected_jquery

jquery code to determine whether checkbox is selected_jquery

WBOY
Release: 2016-05-16 18:18:16
Original
1229 people have browsed it
Copy code The code is as follows:

//Whether it is selected or not, verify that there is a selected return true, otherwise return false
function mycheckbox() {
var falg = 0;
$("input[name='soft[]']:checkbox").each(function () {
if ($( this).attr("checked")) {
falg = 1;
}
})
if (falg > 0)
return true;
else
return false;
}

This is a pretty good method, bookmarked.
The following function is a supplement to the above:
Copy code The code is as follows:

That's how it was originally written. How to write jq1.42.
Secondly, it is recommended that your logic processing
function mycheckbox() {
var falg = 0;
$("input[name='soft[]']:checkbox").each(function () {
if ($(this).attr("checked")) {
falg =1;
return false;
}
})
if (falg > ; 0)
return true;
else
return false;
}

The following is a simple judgment
jquery core judgment statement judgment statement

if($('input:checkbox').attr("checked")==true)

Everyone knows that in html, if a checkbox is checked, it is checked= "checked".
But if we use jquery alert($("#id").attr("checked")), it will prompt you that it is true instead of checked
So many friends judge if($("#id"). attr("checked")=="true") This is wrong. In fact, it should be if($("#id").attr("checked")==true)

The example includes Let’s take a look at a few functions.





Code

Copy code The code is as follows:




New Document












checkbox1

checkbox2

checkbox3

checkbox4

checkbox5

checkbox6

checkbox7

checkbox8



复主代码 代码如下:

/************단일 확인란에서 모두 선택*************************/
function clickCheckbox() {
if($("#checkPathAll").attr("checked"))
{
$("input[name='checkPath']").each( function() {
$(this).attr("checked", true)
});
}
else
{
$("input[name='checkPath']").each(function() {
$(this).attr("checked", false )
});
}
}
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