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!

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

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