How does jQuery obtain all values of the same class label (which cannot be obtained by default )?
This problem happens during development because jQuery always returns only the value of the first class label, so it cannot meet our requirements.
For example:
Copy codeThe 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.
Copy codeThe 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 ();
});
How does jquery obtain the ID value of a sub-tag?
There is a css selector in jquery.
The code is roughly as follows:
$ (". Top1div"). each (function (){
$ (This). children (). each (
Alert ($ (this). attr ("id "));
);
});
It should not be wrong, but I did not test it.
How does jquery obtain any of multiple tags?
Any one of multiple tags?
You can choose from the jQuery selector,
$ ('# Xid') is used to query the page elements with the specified ID as "XID ".
$ ('. Cls') is used to query the page elements whose specified style class is "cls ".
$ ('Table tr td ') is used to search for table-> tr-> td by level, and returns all td
$ ('Table tr td: nth-child (2) ') returns the content of 2nd columns in the table
......
Note that jQuery looks for a set and may have multiple page elements. Use the get function to retrieve one of them.
For example, use $ ('table tr td '). get (1) to retrieve the second td.