CheckBox selection and full selection in jquery

Source: Internet
Author: User

/**
* Select All Events
* @param an array of idlist storage IDs
* @param _this Object
* @param label to store IDs
*/
function SelectAll (Idlist,_this,label) {
var boxs = $ ("Input.select-single");//All Product records
is selected
if (_this.prop ("checked")) {
Boxs.prop ("Checked", true);//check box all selected
Boxs.each (function () {
if ($.inarray (), Val (), idlist) < 0) {//idlist does not contain the current ID value, add
Idlist.push ($ (this). Val ());
}
});
}else{
Cancel All
Boxs.prop ("Checked", false);//check box unchecked
Removes the current ID from the idlist array
Boxs.each (function () {
var index = $.inarray ($ (this). Val (), idlist);
if (index >= 0) {//idlist contains the current ID value, delete
Idlist.splice (index,1);
}
});
}
$ (label). Val (Idlist.join (","));//Writes the currently selected commodity primary key to the hidden domain gid
}

/***
* Radio Events
*/
function Selectsingle (Idlist,_this,label) {
if (_this.prop ("checked")) {//Radio selected
if ($.inarray (_this.val (), idlist) < 0) {//idlist does not contain the current ID value, add
Idlist.push (_this.val ());
}
if (_this.parents ("#list-table"). Find (". Select-single"). Length = = _this.parents ("#list-table"). Find (". Select-single:checked "). Length) {
When all check boxes are selected, the Select all check box is selected
_this.parents ("#list-table"). Find (". Select-all"). Prop ("checked", true);
}
}else{//The Radio check box unchecked
Removes the current ID from the idlist array
var index = $.inarray (_this.val (), idlist);
if (index >= 0) {//idlist contains the current ID value, delete
Idlist.splice (index,1);
}
_this.parents ("#list-table"). Find (". Select-all"). Prop ("checked", false);
}
$ (label). Val (Idlist.join (","));//Writes the currently selected commodity primary key to the hidden field ID
}

Select All Events
$ (". Select-all"). Click (function () {
var _this = $ (this);
SelectAll (Idlist,_this, ". Inner-section. List-title #ids");
});
//Radio Events
$ (". Select-single"). Click (function () {
var _this = $ (this);
Selectsingle (Idlist,_this, ". Inner-section. List-title #ids");
});

CheckBox selection and full selection in jquery

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.