We usually do the project when the operation of the form is unavoidable, using JS. Of course, we can also use jquery,jquery is a very good plug-in, simplifying the vast majority of JS, using it can be very easy to operate the form. Let's see how we can use jquery to determine whether a checkbox is selected
Method One:
Summary of operations related to jquery checkbox, jquerycheckbox
Operations related to jquery checkbox-select all, reselect, and retrieve all selected checkboxes
1. Select All
$("#btn1").click(function(){ $("input[name='checkbox']
1
2. $ ("# select_id"). val (4); // Select an item whose Value is set to 4.
3. $ ("# select_id option [text = 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery.
JQuery adds/deletes Select Option items:
Syntax explanation:
1. $ ("# select_id"). append ("
Text"); // Append an Option to Select (drop-down)
2. $ ("# select_id"). prepend (
attr more jquery version cache prop
1. Determine if checkbox (CheckBox) is selected
Many friends judge if ($ ("#id"). attr ("checked") = = "true") this is wrong and should actually be if ($ ("#id"). attr ("checked") ==true)
if ($ ("#id"). Is (": checked") = = True)
2. Select All
$ ("[name = Chkitem]:checkbox"). attr ("
jquery Fetch Radio The value of the radio button
Copy Code code as follows:
$ ("Input[name= ' Items ']:checked"). Val ();
another: Determine if Radio is selected and gets the selected value
As shown below:
Copy Code code as follows:
function Checkradio () {
var item = $ (": radio:checked");
var len=item.length;
if (len>0) {
Alert ("yes--selected value is:" +$
Jquery APIs provide the following methods to apply the disabled and readonly attributes to elements:
1. readonly
$ ('Input '). ATTR ("readonly", "readonly") // set the input element to readonly $ ('input '). removeattr ("readonly"); // remove the readonly attribute of the input
all Select, the function of the inverse chooses, direct post code, oneself tidy up.
Either way, it's easier to choose between two methods.
Here is a look at the jquery implementation checkbox check box select/all do not select the method. While using JavaScript is easy to implement, the code is very cumbersome.
Let me introduce you to some of your friends about how to use
This morning, the beautiful test sister raised a strange bug, said I a function checkbox in and out, such as the first time to open a tick, the nth opening may not be selected.Think of a close contact with the beauty of the opportunity, immediately chicken move up.After a couple of layers of stripping cocoon (da da Jiang You), finally know the reason: attr () in two times check box, invalid.For example, the following HTML page, a little "check", two p
Solve the problem that all checkbox selections in the jquery operation cannot be selected.Solve the problem that all checkbox selections in the jquery operation cannot be selected.Recently, I used jquery to operate checkbox in my
= 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery.JQuery adds/deletes Select Option items:Syntax explanation:1. $ ("# select_id"). append ("Text"); // Append an Option to Select (drop-down)2. $ ("# select_id"). prepend ("Select"); // Insert an Option for Select (first position)3. $ ("# select_id option: last"). remove (); // Delete the largest Option (last) index value in Select)4. $ ("# select_id option [index = '0']").
= 'jquery ']"). attr ("selected", true); // set the Select Text value to jQuery.JQuery adds/deletes Select Option items:Syntax explanation:1. $ ("# select_id"). append ("Text"); // Append an Option to Select (drop-down)2. $ ("# select_id"). prepend ("Select"); // Insert an Option for Select (first position)3. $ ("# select_id option: last"). remove (); // Delete the largest Option (last) index value in Select)4. $ ("# select_id option [index = '0']").
display status, tangled up for a long time, can not find the reason. Positive solution: Later by the idol direction, the original jquery version of the problem. I manipulate attributes with $ ("* *"). attr ("Attrname"); the jquery version uses 1.9, which is a compatibility and stability issue. The jquery API clearly shows that 1.6+
The example of this article describes the method of implementing the CheckBox selection in jquery. Share to everyone for your reference. The specific analysis is as follows:
Select and deselect all operations through a checkbox, and if processed through toggle, a checkbox cannot display a check mark.
Use the Click ev
When we use js to implement web operations, full selection, no selection, and invert selection of multiple selection boxes are the most common functions, this batch operation is especially required when there is a large amount of data to bring convenient and quick services to users.
In the following example, jquery is used to implement the function of Selecting All, not selecting all, And deselection for the check
Jquery can obtain the implementation code of the form text, areatext, radio, checkbox, and select values. For more information about jquery, see. All are required. Jquery radio, checkbox, select, radio, checkbox, select, and relat
Jquery can obtain the implementation code of the form text, areatext, radio, checkbox, and select values. For more information about jquery, see. All are required. Jquery radio, checkbox, select, radio, checkbox, select, and relat
Jquery checks whether radio, selelct, and checkbox are selected and obtains the summary of the selected value methods. jqueryselelct
Jquery returns the value of the radio button.Copy codeThe Code is as follows:$ ("Input [name = 'items ']: checked"). val ();In addition, determine whether radio is selected and obtain the
jquery takes radio the value of the radio button $ ("Input[name= ' Items ']:checked"). Val (); Another: Determine if Radio is selected and gets the selected value as follows:functionCheckradio () {varItem = $ (": radio:checked"); varlen=item.length;if(len>0) {alert ("yes--selected value is:" +$ (": radio:checked"). Val ()); }} jquery Radio value,
1. Get Selected items for checkbox
2. CheckBox option Selection of the optional reverse operation
CheckBox code snippet for the test:
Copy Code code as follows:
One: First, 1th, get the checkbox's selected item. Most of the methods found on the Web use each to obtain:
Copy Code code as follows:
$ ("
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.