Summary of common and important jQuery methods_jquery
1.jquery data(name)
The data() method appends data to the selected element, or obtains data from the selected element.
$("#btn1").click(function(){ $("div").data("greeting", "Hello World"); }); $("#btn2").click(function(){ alert($("div").data("greeting")); });
2.jquery arguments
arguments is a reference to the actual parameter object, which is an array-like object.
The index of arguments increases from 0, 1,2,...., corresponding to the actual parameters one by one.
arguments.length attribute represents the number of actual parameters
arguments must not be an array, but an object that is long and looks like an array, although it also has a length attribute
Arguments will be found in every function. Therefore, arguments will only find their own arguments internally and cannot refer to outer arguments
// 求圆形面积,矩形面积, 三角形面积 function area () { if(arguments.length == 1) { alert(3.14 * arguments[0] * arguments[0]); } else if(arguments.length == 2) { alert(arguments[0] * arguments[1]); } else if(arguments.length == 3) { alert(arguments[0] + arguments[1] + arguments[2]); } else { return null; } } //调用 area(10,20,30);
3.jquery target() event.target
Thetarget attribute specifies which DOM element triggered the event.
$("p, button, h1, h2").click(function(event){ $("div").html("Triggered by a " + event.target.nodeName + " element."); }); <p></p> <button></button> <h1></h1> <h2></h2> //当点击p标签的时候显示:点击事件由 P 元素触发 ....
4.jquery trigger(event,[parameter 1, parameter 2,...])
Thetrigger() method triggers the specified event type of the selected element. (Events can be customized and parameters can be passed) Custom events are very important and useful!
//myEvent为自定义事件名 $("#p1").bind("myEvent",function(str1,str2) { alert(str1 + ' ' + str2); }); $("#p1").trigger("myEvent",["Hello","World"]); //也可以这样写: $("#p1").bind("myEvent",function(str1,str2) { alert(str1 + ' ' + str2); }).trigger("myEvent",["Hello","World"]);
5.js substring(start,stop)
Thesubstring() method is used to extract characters between two specified subscripts in a string.
The substring returned by thesubstring() method includes the characters at start but does not include the characters at stop.
var str="Helloworld!" document.write(str.substring(3,7)) //结果 lowo var str="Hello world!"//有两个空字符 document.write(str.substring(3,7)) //结果 lo //两者的结果有区别,字符串之间的空字符串占用索引!
Look clearly, there is no r character at the stop!
Important: Unlike the slice() and substr() methods, substring() does not accept negative arguments.
6.js slice(start,stop)
Theslice() method extracts a certain part of a string and returns the extracted part as a new string. Same as the substring above, excluding the characters at the stop;
Another difference is: start and stop can use negative numbers! That is, -1 refers to the last character of the string, -2 refers to the second to last character, and so on.
The data() method appends data to the selected element, or obtains data from the selected element.
The above is the entire content of this article, I hope you all like it.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

This article explores effective use of Java's Collections Framework. It emphasizes choosing appropriate collections (List, Set, Map, Queue) based on data structure, performance needs, and thread safety. Optimizing collection usage through efficient

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion
