JQuery always returns the value of the first class label, so it cannot meet our requirements. How does jQuery obtain all the values of the same class label, I will share with you the following method. This problem occurs during development. Because jQuery always returns only the value of the first class label, it cannot meet our requirements.
For example:
The Code is as follows:
Var btn = jQuery ('. btn'). val ();
Only the value of the html element whose first class label is btn is obtained.
Obtain the values of all html elements of a group of class tags. You have to use jQuery's each traversal.
The Code is as follows:
Var btns = new Array (); // You can also specify var btns = [];
JQuery ('. btn'). each (function (key, value ){
Btns [key] = $ (this). val ();
// Or you can write it like this:
// Btns [key] = $ (value). val ();
});