Use jquery to determine the selection of a checkbox.There is a problem when using the $ (). attr (' checked ') to select and deselect the 12th time, but the third time, there is no response at All.After that, $ () is Used. prop () yes, it is.//Select All and select All$ ("#allorone_check"). Click (function(){ if(!$( this). Hasclass ("selectall") {console.log ($ ("#lxyzlist input[type=checkbox]")); $(
Recently, I used jquery to operate checkbox in my work. I used the following method to select all and invert:Copy codeThe Code is as follows:Var ischecked = allCheckObj. is (': checked ');Ischecked? ChecksObj. attr ('checked', true): checksObj. attr ('checked', false ); There was no problem with ie during debugging. Considering compatibility, I tried firefox and encountered a problem. Therefore, we did the
This article is mainly on the jquery to determine whether checkbox (check box) is selected, as well as SELECT, reverse the implementation of the Code is introduced, the need for friends can come to the reference, I hope to be helpful to everyone jquery Determines whether the checkbox (check box) is selected: if ($ ("
jquery three ways to judge checked:. attr (' checked): //See version 1.6+ return: "Checked" or "undefined"; 1.5-return: TRUE or False.prop (' checked '): 16+:true/false.is (': Checked '): //All versions: true/false//don't forget the colon. The several ways in which jquery assigns checked: All jquery versions can be assigned this way:/$ ("# CB1 "). attr (" Ch
jquery checked three ways to determine:
. attr (' checked)://See version 1.6+ return: "Checked" or "undefined"; 1.5-return: TRUE or False
. Prop (' checked ')://16+:true/false
. Is (': Checked ')://All Versions: true/false//don't forget the colon!
Several ways to checked jquery assignment:
All jquery versions can be assigned this way:
$ ("#cb1"). attr ("Che
= $ ("); $ (". Selector2"). Append (option);});jquery sets the text and value selected for select:Syntax Explanation:$ ("#select_id"). Get (0). selectedindex=1; // Set the Select index value to 1 to select $ ("#select_id"). Val (4); // Sets the value of select to 4 for the item selected true); // set the text value of select to the item selected for jquery1. Gets the value of a set of radio selected itemsVar2. Get the text of select selecte
jquery Radio value, checkbox value, select Value, Radio selected, CheckBox selected, select selected, and its relatedGets the value of a set of radio selected itemsvar item = $ (' input[@name =items][@checked] '). Val ();Gets the text of the Select selected itemvar item = $ ("select[@name =items] option[@selected]"). Text ();The second element of the Select drop-
The jquery method is as follows: Copy codeThe Code is as follows:Function CheckAll (val ){$ ("Input [name = 'chkjob']"). each (function (){This. checked = val;});$ ("# ChkAll"). attr ("checked", val); // you can specify the status of the Select All button.} Val this parameter specifies the selection status of the all-selected button.Name = 'chkjob' is the checkbox name in the list.ChkAll is the name of the
Because of the jquery version problem, take the checkbox of the selected state value, was killed miserably ...
The following is an online summary (http://www.wufangbo.com/jquery-pan-duan-checked/):
The three ways jquery judges checked:
. attr (' checked ')://See version 1.6+ return: "Checked" or "undefined"; 1.5-r
The jquery method is as follows:
Copy Code code as follows:
Function Checkall (val) {
$ ("Input[name= ' Chkjob ']"). each (function () {
this.checked = val;
});
$ ("#chkAll"). attr ("Checked", Val);//Set all Select button Status
}
Val, this parameter passes the selection state of the full selection button.
Name= ' Chkjob ' This is the name of the checkbox in the list
Chkal
The three ways jquery judges checked:. attr (' checked)://See version 1.6+ return: "Checked" or "undefined"; 1.5-return: TRUE or False. Prop (' checked ')://16+:true/false. Is (': Checked ')://All Versions: true/false//don't forget the colon!Several ways to checked jquery assignment:All jquery versions can be assigned this way:$ ("#cb1"). attr ("Checked", "checke
The jquery method is as follows:
CopyCode The Code is as follows: function checkall (VAL ){
$ ("Input [name = 'chkjob']"). Each (function (){
This. Checked = val;
});
$ ("# Chkall"). ATTR ("checked", Val); // you can specify the status of the Select All button.
}
Val this parameter specifies the selection status of the Select All button. name = 'chkjob' indicates the checkbox name in the list. chkall
First to show you the effect of the picture, if you feel good, please continue to refer to the implementation code.
HTML code:
jquery code:
Note: Due to the changes in the jquery version, the new version appears only once, the older version is OK, the new version can not use attr to set the selected state, the first solution is to use the JS native method This.checked=true/f
Usage: We first save the following JS to have a file, then call, indifferent you can also write directly in the page, recommended the use of the former, convenient reuse:
Copy Code code as follows:
(function ($) {
$.fn.checkgroup = function (options) {
Merge settings
Settings=$.extend ({
Groupselector:null,
GroupName: ' Group_name ',
Enabledonly:false
},options | | {});
var ctrl_box=this;
Allow a group selector override option
var grp_slctr = (settings.groupselector==
This article summarizes some methods and techniques for using the check box for jQuery operations. It is very simple and practical. For more information, see. 12 tips for jquery operation check box (checkbox.
1. Obtain the selected items of a single checkbox (three methods)
$("input:checkbox:checked").val()
Or
$("i
This article mainly summarizes the 12 tips of the jquery check box (checkbox). If you need a friend, please refer to them and hope to help you.
1. Obtain the selected items of a single checkbox (three methods)$ ("Input: checkbox: checked"). val ()
Or
$ ("Input: [type = 'checkbox
When JQuery. attr () and. prop () are used correctly, the correct method for JQuery to get the checkbox status is jquery. attr
Google Chrome's return value for $ ("# checkboxId"). attr ("checked") is undefined and cannot be understood. Many articles on the Internet say this is correct ...... After Google searched for
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.