1. Introduction to jQueryWhat is jQuery and what does it do?
Usage characteristics of various selectors: There are five basic selectors: There are 4 types of relational selectors: There are 8 basic filter selectors: There are 4 content filter selectors: There are 2 types of visibility filter selectors: There are 8 attribute selectors: Sub-element filter selector (4 types) Form attribute filter selector (4 types) Form selector (11 types) 2. jQuery selector2.1 Five basic selectors// 5 basic selectors $(".div"); // class selector $("div"); // tag selector $("#box"); // id selector $("*"); // wildcard selector $("div,p,img"); // merge selector 2.2 Four types of relationship selectors//4 types of relationship selectors $("div p"); //descendant selector $("div>p"); //child selector $("div+p"); //direct sibling selector $("div~p"); //simple sibling selector 2.3 8 basic filter selectors// 8 basic filter selectors $(":first");//First element $(":last");//Last element $(":not(selector)");//Exclude selector $(":even");//Select even rows $(":odd");//Select odd rows $(":eq(index)");//Elements with index equal to index $(":gt(index)");//Elements with index greater than index $(":lt(index)");//Elements with index less than index 2.4 4 types of content filter selectors// 4 types of content filter selectors $(":contains(text)"); //Matches elements that contain the given text $(":empty"); //Matches all empty elements that do not contain child elements or text $(":has(selector)"); //Matches elements that contain the selector $(":parent"); //Matches elements that have child elements or text 2.5 Two types of visibility filter selectors// 2 types of visibility filter selectors $(":hidden"); // matches all invisible elements, or elements of type hidden $(":visible"); // matches all visible elements 2.6 8 types of attribute filter selectors// 8 types of attribute filter selectors $("[attribute]"); //Match elements with attribute attributes $("[attribute=value]"); //Match elements with attribute values equal to value $("[attribute!=value]"); //Match elements with attribute values not equal to value $("[attribute^=value]"); //Match elements with attribute values starting with certain values $("[attribute$=value]"); //Match elements with attribute values ending with certain values $("[attribute*=value]"); //Match elements with attribute values containing certain values $("[attributeFilter1][attrbuteFilter2]"); //Compound attribute filter selector, used when multiple conditions need to be met at the same time 2.7 Sub-element filter selectors (4 types)//Sub-element filter selector (4 types) $(":nth-child(index/even/odd)") //Select the index-th child element under each parent element $(":first-child"); //Select the first child element of each parent element $(":last-child"); //Select the last child element of each parent element $(":only-child"); //If an element is the only child element of its parent element, it will be matched 2.8 Form attribute filter selectors (4 types)//Form attribute filter selector (4 types) $(":enabled");//Select all enabled elements$(":disabled");//Select all disabled elements$(":checked");//Select all selected elements$(":selected");//Select all selected elements 2.9 Form selectors (11 types)// Form selector (11 types) $(":input");//Select all input/textarrea/select/button elements$(":text");//Select all single-line text boxes$(":password");//Select all password boxes$(":radio");//Select all radio buttons$(":checkbox");//Select all check boxes$(":submit");//Select all submit buttons$(":image");//Select all image buttons$(":reset");//Select all reset buttons$(":button");//Select all buttons$(":file");//Select all upload fields$(":hidden");//Select all invisible elements 3. DOM manipulation in jQuery3.1 Text Operation// Text operation $("p").html(); // Equivalent to p.innerHtml in DOM; $("p").text();//Equivalent to p.innerText in DOM; 3.2 Value Operations// Value operation $("input:eq(5)").val(); //Equivalent to input.value in DOM; $("input:eq(6)").val("aaa"); //Set attribute value 3.3 Attribute Operation// Attribute operation $("#box").attr('name'); //Get the name attribute $("#box").attr('name',"aaa"); //Add the name attribute and value $("#box").removeAttr('name'); //Delete the name attribute $("#box").prop('checked'); //When getting a single attribute, use prop to get false and true 3.4 Class Operations// Class operation $("#box").attr("class","");//Get and set $("#box").addClass("class","");//Append class name $("#box").removeClass("class","");//Remove class name $("#box").removeClass();//Remove all class names $("#box").toggleClass("main");//Switch main class name $("#box").hasClass("main");//Is there a certain class name 3.5 Style Operation//Style operation $("#box").css("color"); //Read CSS style value $("#box").css({"propertyname":"value","propertyname":"value"}); //Set multiple styles at the same time 4. Node Operation4.1 Traversing nodes//Traverse nodes$("#box").children();//Get child nodes$("#box").children("div");//Get div child nodes$("#box").prev();//Find a brother immediately above$("#box").prevAll();//Find all brothers immediately above$("#box").prevAll("div");//Find all div brothers immediately above$("#box").next();//Find a brother immediately below$("#box").nextAll();//Find all brothers immediately below$("#box").nextAll("div");//Find all div brothers immediately below$("#box").parent();//Find parent node 4.2 Filter Nodes//Filter nodes $("ul").find(".a");//Search $("ul li").filter(".a");//Filter 4.3 Create, Insert, and Delete// Create, insert, delete var lis=$("<li title='aaa'>aaa</li>");//Create//Internally add parent.append(lis);//Add to the end of the parent box parent.prepend(lis);//Add to the head of the parent box//Externally add box.after(lis);//Add after the box box.before(lis);//Add before the box//Delete DOM elements $("ul").remove();//Completely delete, delete both ul and li $("ul").empty();//Just clear the contents of ul, ul still exists $("li").remove(".one");//Delete class="one" in li 5. jQuery Events// jQuery event // Difference from JS // window.onload and $(document).ready() //Difference 1: The former is executed after the page is fully loaded, while the latter is executed after the DOM is loaded. The latter takes precedence over the former. //Difference 2: When the former appears multiple times, the last one will overwrite the previous one. When the latter appears multiple times, they will be merged. //Difference 3: Is there an abbreviation: window has no abbreviation, document has an abbreviation. //Abbreviation: $().ready(function(){...}) // $(function(){....}) //Event binding: $(selector).on(event type, callback function) $("ul li").on("click",function(){alert(1);}); // jQuery and Ajax // get method $.get(url,data,success(response,status,xhr),dataType); // post method $.post(url,data,success(data, textStatus, jqXHR),dataType); SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Web Design Tutorial (5): Web Visual Design
>>: How to modify the "Browse" button of the html form to upload files
Tomcat's default log uses java.util.logging, ...
In the previous article, we explained how nginx r...
The server reports an error 502 when synchronizin...
I want to achieve a situation where the width of ...
The MySQL built-in date function TIMESTAMPDIFF ca...
This article example shares the specific code of ...
Preface When the HTML structure of a page contain...
Table of contents Preface start React Lifecycle R...
Network security is a very important topic, and t...
Preface As a basic data structure, arrays and obj...
The previous article was a simple review of the B...
Table of contents Vue3 + TypeScript Learning 1. E...
Illustrated CentOS 7.3 installation steps for you...
The default varchar type in MySQL is case insensi...
The meaning of key_len In MySQL, you can use expl...