Operation instance analysis of jQuery selectors and attribute objects

This example tells the operation of the jQuery selector and attribute object. Share to everyone for reference, specifically:

  jQuery-selector      function testID () {// Using the ID to get the object, pay attention to the use of IDs must be added #, after all, is your custom name var INP = $ ("# INP"); Alert (INP ); // Returns the acquired object type [object object] Alert (INP.VAL ()); // You can get the values ​​of the object in real time, Note: INP is in nature is an array, so it doesn't have a Value property ( Value is an object's properties), we use its VAL method Alert (Inp.Length); // Returns the length of the array} Function TestTTTTTTTTTTTTTTARGET () {// Using the label to get the object VAR TA = $ ("input"); Alert Ta.val ()); // Print the value value Alert (TA.LENGTH) of the element of the first INPUT; // Returns the length of the array, is the number of all INPUT tags} function testclass () {// Utilization Gets the object, feeling, and CSS's corresponding selectors, use the class selector, use. Class name VAR CL = $ ("symbon"); Alert (cl.val ()); Alert (cl.length); / / Returns the number of this class attribute} Function TestComponent () {// Using a combination of various methods to get objects VAR Al = $ (". ComMMON, INPUT"); Alert (al.val ()); Alert (Al).length); // Returns all types of numbers} Function TestComponent () {// Using a combination of various methods to get objects VAR Al = $ (". comMMON, INPUT"); Alert (al.val ()); Alert (al.length); // Returns all types of sum} Function TestChild () {// Gets objects of the parent class VAR FA = $ ("# showdiv> input"); Alert (fa.val ()); Alert (fa.length);} function testcj () {// Test hierarchy // Directly obtains its subview, using jQuery method var C1 = $ ("Input: first"); Alert (C1.VAL ()) ; // Use data to obtain // Alert (c1.length); // Using non-jQuery method var C2 = $ ("infut"); Alert (C2 [0] .value); // We The object of JS is obtained, not an array, we have obtained object value from it} function testcj2 () {// Test hierarchy var TDS = $ ("td"); Alert (tds.length); // Return value Number It is 6 VAR TDM = $ ("TD: NOT (TD [Width])"); // Returned Object is an array of Alert (TDM.LENGTH); The return value is 4, minus the number of Width attributes in TD (TDM.html ()); // Returns data inside the tag, equivalent to the attribute of JS innerHTML} // Operation data Function Testfield () {// Get the object var fl = $ ("# INP"); Alert (Fl.attr ("Type") + ": + fl.attr (" Value "+": + fl.val ()); / / Declaration here, the corresponding use of Attr can obtain a series of properties of the object, where Value can only obtain its default existing value, but use the array object .val () get real-time Value} Function TestChange () {// Get Object VAR F2 = $ ("# INP"); // Modify Object Properties F2.attr ("Type", "Button"); // Note It inside it is quoted , One is used to change the properties to modify, the other is used to modify the value}   .common {} #Showdiv {Width: 200px; Height: 100px; Border: Solid 1PX;} Input [type = text] {margin-top: 10px; width: 80px; margin-left: 10px;}   jQuery-selector     


Interested friends can use : http: //tools.jb51.net/code/htmljsrun Tested the above code running effect. More about jQuery related content, readers can be viewed on this site: "jQuery page element operation skills summary", "jQuery common event usage and skill summary", "jQuery common plug-in and usage summary", "JQuery extension skill summary" and "JQuery Selector Summary" I hope this article will help you jQuery program.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment

online HTML / CSS / JavaScript code running tool