$ ("#selectInverse"). Click (function() {$ (": CheckBox"). each (function() {$ (this). attr (" Checked ",!$ (this). attr (" checked ")); }) });A more troubled checkbox two times the failure problem was originally the issue of the rise of the jquery version. Like people, the problem comes.1.6+ jquery uses propto replace
Parameter description:
1.checkName: Indicates the name value of the check box
2.updateFile: Indicates that the database needs to manipulate the field, the project needs to update a field, so this place is the need to update the field, can be changed depending on the situation
3.formName: Represents the name value of the page form, if the program is written in the page, you can directly write the name value of the form, such as Form NAME=FORM2, you can form2.action= xxx; Form2.submit ();
But if y
=false.
Thought is such a train of thought, if who has a better way to paste up, we learn to study together.
The methods used in jquery:
First (): element one;
Nextall (): All elements after XX: mainly to remove the header of the first row
Children (): Find child elements;
Toggleclass (); Toggle Style
attr (): Add checked attribute to checkbox;
The main implementation code:
Copy Code code as
In the HTML checkbox, the selected word will have attributes checked= "checked".
If a checkbox is selected, the value alert ($ "#xxx" for the CheckBox's property "Checked") is printed "true" instead of "checked" attr ("checked").
If not selected, print out "undefined". That's weird, isn't it? Keep looking!
Don't try to make such judgments:
The code is as follows
Copy Code
if
Just learn jquery, in doing a checkbox to select all the time encountered a problem, using the attr () method, you can only successfully select and deselect all the time, the second is not, such as the following$("#chkAll"). Click (function () {if( This.checked==true){ $("#tab input[type= ' checkbox ']"). attr ("checked",true); }Else{
If you use jquery 1.6, the code if ($ (elem). attr ("checked")) will get a property (attribute) that does not change the check box to be selected and selected. It is used only to store the default or selected property's initial value. In order to maintain backward compatibility, the. attr () method starts with the JQuery 1.6.1+, in addition to returning the property value, the property attribute is also upd
In the HTML checkbox, the selected word will have attributes checked= "checked".
If a checkbox is selected, the value alert ($ (#xxx) for the property "checked" of the checkbox for alert is printed "true" instead of "checked" attr ("checked").
If not selected, print out "undefined".
Notice the red part.
$ ("#chekbox"). Sttr ("checked")//should is print "tru
If you use jquery 1.6, code if (elem). attr ("Checked"), you will get an attribute that does not change the check box is selected and selected. It is simply used to store the initial value of the default or selected property. To maintain backward compatibility, the. attr () method starts with the JQuery 1.6.1+ and, in addition to returning property values, the property properties are updated, so the Boolean
", 'checked'); // set single checked value = 2 to the selected status. (Note that there is no space in the middle)
3. Check box:$ ("Input [@ type = checkbox] [@ checked]"). Val (); // obtain the value of the first check box.$ ("Input [@ type = checkbox] [@ checked]"). Each (function () {// Since multiple check boxes are selected, You can output them cyclically.Alert ($ (this). Val ());});
$ ("# CHK1"). ATTR
Summarize the checkboxes in the actual development of the common attributes and events in conjunction with jquery:
1,checkbox how the selected state changes:
$ (function () {$ ("#basketBall"). Change (function () {Alert ("BASEketball changing");});})
2,checkbox selected:
Select all the checkboxesThe first type: $ ("input[type= '
Jquery traverses the checkbox to obtain the value of the selected item
This article mainly introduces Jquery to traverse the checkbox to obtain the value of the selected item. For more information, see
Source code:
The Code is as follows:
JQuery (function ($ ){
$ ("Input [n
The solution for JQuery to set the second checkbox value is invalid, jquerycheckbox
In this mvc asp. NET project, I use jquery ajax to transmit data to the controller control layer in the background and return data to JQuery.
First, you must clear the checkbox selection. B
JQuery cannot set the checkbox check box selection cause resolution, jquerycheckbox
Why does jQuery fail to set the checkbox check box:Many coders may encounter this strange situation, that is, they use jQuery to set the checkbox
Copy codeThe Code is as follows:$ ("Input"). attr ("checked", "checked ") After setting, the checkbox does not change to the selected status. After debugging with chrome, you can see that the checkbox does have the checked attribute and the value is checked, but the page is still displayed as unselected.Copy codeThe Code is as follows:$ ("Input"). prop ("checked", true ); The differences between ttributes a
JQuery API:
Each (callback):: performs a function as a context for each matching element.
: Checked: matches all selected selected elements (check box, radio box, etc., excluding option in select)
Js:
JS Gets the checkbox value
var obj = document.getelementsbyname ("interest");//Selects all name= "Interest" objects, returns the array
var s= '; If you define VAR s in this way, the
Copy Code code as follows:
$ ("input"). attr ("Checked", "checked")
After setting the checkbox does not become selected, with Chrome debugging, the checkbox does have the Checked property, and the value is checked, but the page display is still unchecked
Copy Code code as follows:
$ ("input"). Prop ("checked", true);
The difference between ttributes and properties i
Jquery checkbox Click Event
$ ("# Checkboxbrand input [type = 'checkbox']"). on ('click', function () {alert ("asdsad") ;}) under checkboxbrand, there is a dynamic Paging for checkbox, the above method does not trigger the event $ ("body") by clicking the check box "). delegate ("# checkboxbrand input [type = '
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.