Jquery events and binding events are both very important knowledge. This article mainly introduces the relevant knowledge of jquery events and binding events, which has a good reference value. Let's take a look with the editor below, I hope it can help everyone.
1. First, let’s take a look at the commonly used ways to add events:
<input> <script> function shao() { alert("msg is showing!"); } </script>
The most commonly used way for us to add events is to add onclick element attributes to elements
The disadvantage of this method is:
can only be used for one event processing function. In the event processing function method, the way to obtain the event object is different.
Events in jQuery
ready event:
When the page is loaded, execute the function:
<script> $(document).ready(function(e){ alert(document.getElementById("aa").innerHTML); //若是要写function方法,不可以在里面写 }) //要在外面写 </script>
This method can be called wherever it is written;
Mouse event :
<script> $("#aa").click(function(){ alert("点击事件"); }) $("#aa").dblclick(function(){ alert("双击事件"); }) $("#aa").mouseover(function(){ alert("鼠标移上") }); $("#aa").mouseout(function(){ alert("鼠标离开"); }) $("#aa").mousemove(function(){ alert("鼠标移动"); }) $("#aa").mouseup(function(){ alert("鼠标抬起"); }) $("#aa").mousedown(function(){ alert("鼠标按下"); }) 键盘按键按下:给id加没有作用,需要给整个页面加所以用$(document) $(document).KeyEvent(function(){ alert("鼠标离开"); }) </script>
Form element events:
<script> $("#shao").focus(function(){ alert("获得焦点"); }) $("#shao").blur(function(){ alert("失去焦点"); }) $("#shao").change(function(){ alert("值发生变化,change事件"); }) $("#shao").keydown(function(){ alert("键盘按下"); }) </script>
2. Binding events (hanging events):
Events that can dynamically change buttons;
What Is it dynamic binding?
Dynamic binding refers to dynamically added DOM nodes or html elements, which do not exist when they are initially run. If you want to add events to these dynamically added nodes, you must use jquery's on method to bind the events.
bind() adds one or more event handlers to the matching element.
Usage:
$(selector).bind(event,data,function)
Note: The bind() function can only handle events for existing elements. Set up the
code: first write two buttons:
<p>hello</p> <!--<input type="text" id="shao" />--> <input> <input>
First operate the click and hang event:
<script> //挂事件, $("#btn1").click(function(){ //点击挂事件,给p绑定一个事件: $("#aa").bind("click",function(){ //bind绑定事件 alert("点击"); }); //括号里两个参数,第一个是事件类型(事件名称),第二个参数是要执行的代码 }) </script>
In this case, click and hang the event:
Remove event button:
<script> //移除事件; $("#aa").click(function(){ //点击移除事件;把p里面的事件移除掉 $("#aa").unbind("click"); //unbind移除绑定,填一个参数,要移除哪个事件 }) </script>
Click to remove, click the event to cancel aa
3. Event data
General events include events Source and time data:
Event data: At this time, the data will be passed
js simplified, you don’t need to write the event source, because you can get
4. JSON syntax:
JSON structure:
Json is simply an object and an array in JavaScript, so these two structures are objects and arrays, which can be represented by these two structures various complex structures.
(1) Object: The object is represented in js as the content enclosed by "{}", and the data structure is the key-value pair structure of {key: value, key: value,...}, in In object-oriented languages, key is the attribute of the object, and value is the corresponding attribute value, so it is easy to understand. The value method is object.key to obtain the attribute value. The type of this attribute value can be a number, a string, an array, or an object. Several kinds.
(2) Array: The array in js is the content enclosed by square brackets "[]". The data structure is ["java", "javascript", "vb",...], and the value is The method is the same as in all languages, using index acquisition. The type of field value can be numbers, strings, arrays, or objects.
Complex data structures can be combined through the two structures of objects and arrays.
json is a lightweight data exchange format
Quanpin:
JavaScript Object Notation
Definition syntax:
var j = { "one":"111111", "two":"22222" };
Value method:
Index:
//数组的取值方式: alert(j["one"]);//直接取索引的方法
Dot syntax:
//点语法: alert(j.one);
JSON can also be a two-dimensional array:
var j = { "one":"111111", "two":"22222", "three":{"aa":"33333"}, }; //数组的取值方式: //alert(j["one"]);//直接取索引的方法 //点语法: alert(j.one); alert(j.three.aa);
Traverse JSON data:
//遍历 for(var v in j) { //定义一个变量v,把j拿到v里面,关键字不是”as“了,是”in“, alert(v); // 这样便利的是索引 alert(j[v]); // 这样是根据索引来取值 }
json does not have a length attribute, so the for loop is not suitable for json
But for-in is also suitable for arrays
Related recommendations;
Detailed examples of the properties of jQuery event objects
The difference between mouseover and mouseenter in jQuery events
When using on to bind events in jQuery What needs attention
The above is the detailed content of Detailed description of jquery events and binding events. For more information, please follow other related articles on the PHP Chinese website!

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base

JavaScript is the core language of modern web development and is widely used for its diversity and flexibility. 1) Front-end development: build dynamic web pages and single-page applications through DOM operations and modern frameworks (such as React, Vue.js, Angular). 2) Server-side development: Node.js uses a non-blocking I/O model to handle high concurrency and real-time applications. 3) Mobile and desktop application development: cross-platform development is realized through ReactNative and Electron to improve development efficiency.

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.


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

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function