Different jQuery APIs to handle different browser events_jquery
Handling events is a bit difficult part of today's web browsers, and different browsers handle events in different ways. Therefore, to overcome these cross-browser issues, one can leverage jQuery's event handling API.
jQuery is a small JavaScript library that provides a vast API to handle different browser events and effects and much more. Read more about handling browser user interface effects using JavaScript. In this tutorial, we will explore the different APIs of jQuery to handle different browser events.
Page Load Event
Ready (FN),
This is the basis of all types of events that jQuery supports. You may want to set the focus of the form when the page is loaded or do some UI effects.
$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
Event handling
Binding (Type, Data, FN),
You may want to bind an element to any element that handles one or more events (click/double click, etc.). Use this feature in conjunction with custome's event handler for any element.
$("p").bind("click" , function(e) {
var str = "( " e.pageX ", " e.pageY " )";
$("span").text("Click happened! " str);
});
$("p").bind("dblclick", function() {
$("span").text("Double-click happened in " this.tagName);
});
$("p").bind("mouseenter mouseleave", function(e) {
$(this).toggleClass("over");
});
trigger (event, data)
triggers the event on every matched element,
this will also cause the browser to have the same name (if one exists) The default action performed. For example, a function via trigger() will also cause the browser to submit a "submit" of the form. False default behavior can be prevented by returning one of the functions bound to the event.
The triggered events are not limited to browser-based events. You can also customize event trigger binding registration.
$("button:first").click(function () {
update($("span:first"));
});
$("button:last").click(function () {
$("button: first").trigger('click');
update($("span:last"));
});
function update(j) {
var n = parseInt(j .text(), 10);
j.text(n 1);
}
Interactive auxiliary activities
In today’s Web 2.0 applications Program, user intraction processing is very important. jQuery provides some APIs that can be used to handle these interactions. Hover (Multiple) This function provides hover functionality, i.e. when the mouse cursor moves over a matching element, the first specified function is fired. When the mouse moves over the element, the second specified function fires. Also, check where you see if the mouse is still over the specified element (e.g. an image inside a div), if so it will continue to "hover" and not move out (a common behavior when using the mouseout event handler) error.
$("li").hover(
function () {
$(this).append($(" ***"));
},
function () {
$( this).find("span:last").remove();
}
);
Auxiliary for other activities
The following are the functions, Can be used to handle different types of event lists.
blur()
: Triggers the blur event for each matching element.
$("input").blur(function () {
$(this).next("span").css('display','inline').fadeOut(1000);
});
Blur (FN)
: Bind a handler function to the blur event of each matching element.
[code]
$("input").blur(function () {
$(this).next("span").css('display','inline').fadeOut( 1000);
});
(FN)
: Bind a function to the change event of each matching element.
$("select").change(function () {
var str = "";
$("select option:selected").each(function () {
str = $(this).text() " ";
});
$("div").text(str);
})
.change();
Click (FN)
: Function bound to the click event of each matching element.
$("p").click(function () {
$(this).slideUp();
});
$("p").hover(function () {
$(this).addClass("hilite");
}, function () {
$(this).removeClass("hilite");
});
Double-click (FN)
: Trigger the DblClick event for each matching element.
var divdbl = $("div:first");
divdbl.dblclick(function () {
divdbl.toggleClass('dbl');
});
Key (FN)
: Bind a function to the keypress event of each matching element.
$("input").keypress(function (e ) {
if (e.which == 32 || (65 <= e.which & e.which <= 65 25)
|| (97 <= e.which && e.which <= 97 25)) {
var c = String.fromCharCode(e.which);
$("p").append($(""))
.children(":last")
.append(document.createTextNode(c));
} else if (e.which == 8) {
// backspace in IE only be on keydown
$("p").children(":last").remove();
}
$("div").text(e.which);
});
mousedown (FN)
: Function bound to the mousedown event of each matched element.
$("p").mouseup(function() {
$(this).append('Mouse up.');
}).mousedown(function(){
$(this).append('Mouse down.');
});
Scroll (FN)
: Bind a handler function to the scroll event of each matching element.
$("p").clone().appendTo (document.body);
$("p").clone().appendTo(document.body);
$("p").clone().appendTo(document.body);
$(window).scroll(function () {
$("span").css("display", "inline").fadeOut("slow");
});

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



How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

Oracle is a world-renowned database management system provider, and its API (Application Programming Interface) is a powerful tool that helps developers easily interact and integrate with Oracle databases. In this article, we will delve into the Oracle API usage guide, show readers how to utilize data interface technology during the development process, and provide specific code examples. 1.Oracle

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

OracleAPI integration strategy analysis: To achieve seamless communication between systems, specific code examples are required. In today's digital era, internal enterprise systems need to communicate with each other and share data, and OracleAPI is one of the important tools to help achieve seamless communication between systems. This article will start with the basic concepts and principles of OracleAPI, explore API integration strategies, and finally give specific code examples to help readers better understand and apply OracleAPI. 1. Basic Oracle API

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Title: How to deal with Laravel API error problems, specific code examples are needed. When developing Laravel, API errors are often encountered. These errors may come from various reasons such as program code logic errors, database query problems, or external API request failures. How to handle these error reports is a key issue. This article will use specific code examples to demonstrate how to effectively handle Laravel API error reports. 1. Error handling in Laravel

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s
