jQuery is a very popular JavaScript library in front-end development, which can quickly and easily manipulate HTML documents and CSS styles. In jQuery, selectors are a very important and commonly used function, through which you can select elements on the page and then operate on them.
jQuery provides a variety of selectors that can select elements based on their tag names, class names, ID values, attribute values, etc. When the page loads, we usually perform special processing on certain elements, such as showing or hiding certain elements, or binding events.
In this case, you can use jQuery's selector and event binding to achieve this. Here are some commonly used events and selectors.
1. Page loading completion event
In jQuery, the page loading completion event can be bound using the ready() method, which will be executed immediately after the DOM is loaded. The sample code is as follows:
$(document).ready(function() { // 页面加载完成后执行的代码 });
In addition, since ready() is commonly used, jQuery also provides a shorthand form:
$(function() { // 页面加载完成后执行的代码 });
These two forms are completely equivalent and can be loaded on the page. Do something when finished.
2. Selector
1. Basic selector
The basic selector is the simplest form of selector, which can be based on the tag name, class name, and ID value of the element. to select elements.
Select elements based on tag names:
$('p') // 选择所有<p>元素</p>
Select elements based on class names:
$('.my-class') // 选择所有class属性值为my-class的元素
Select elements based on ID values:
$('#my-id') // 选择ID值为my-id的元素
2. Attribute selector
Attribute selector can select elements based on their attribute values, the most commonly used ones are [class^="xxx"] and [class$="xxx"].
Select elements based on the attribute name and attribute value:
$('input[type="text"]') // 选择所有type属性值为text的input元素
Select elements based on the beginning of the attribute value:
$('div[class^="my-"]') // 选择class属性值以my-开头的所有div元素
Select elements based on the end of the attribute value:
$('a[href$=".pdf"]') // 选择href属性值以.pdf结尾的所有a元素
3. Hierarchical selector
The hierarchical selector can select the child elements, parent elements, sibling elements, etc. of an element.
Select the child elements of an element:
$('ul li') // 选择所有ul元素下的li元素
Select the parent element of an element:
$('li').parent() // 选择所有li元素的父元素
Select the sibling elements of an element:
$('li').siblings() // 选择所有li元素的兄弟元素(不包括自己)
4. Form selector
The form selector can select form elements, including text boxes, check boxes, radio buttons, drop-down boxes, etc.
Select all text box elements:
$('input[type="text"]') // 选择所有type属性值为text的input元素
Select all check box elements:
$('input[type="checkbox"]') // 选择所有type属性值为checkbox的input元素
Select all radio button elements:
$('input[type="radio"]') // 选择所有type属性值为radio的input元素
Select all drop-downs Box element:
$('select') // 选择所有select元素
3. Event binding
1. Click event
The click event is one of the most commonly used events and can be bound through the click() method Certainly. The sample code is as follows:
$('button').click(function() { // 单击了button按钮后执行的代码 });
2. Double-click event
The double-click event refers to the event of clicking twice quickly on an element, which can be bound through the dblclick() method. The sample code is as follows:
$('button').dblclick(function() { // 双击了button按钮后执行的代码 });
3. Keyboard events
Keyboard events refer to the events of pressing or releasing keyboard keys on the page, which can be done through keypress(), keydown(), keyup( ) three methods to bind.
4. Mouse events
Mouse events refer to events in which the mouse moves, clicks, double-clicks, presses, releases, etc. on the page. It can be passed through mousemove(), mousedown() , mouseup(), mouseenter(), mouseleave(), hover() and other methods to bind.
5. Page scroll event
Scroll event refers to an event triggered when the user scrolls the page, and can be bound through the scroll() method.
The above are some commonly used events and selectors, which can help us quickly locate elements on the page and perform event binding. Of course, jQuery also provides many other functions and methods, and interested readers can learn and explore on their own.
The above is the detailed content of What to use when loading jquery page using selection event. For more information, please follow other related articles on the PHP Chinese website!

The article discusses useEffect in React, a hook for managing side effects like data fetching and DOM manipulation in functional components. It explains usage, common side effects, and cleanup to prevent issues like memory leaks.

Lazy loading delays loading of content until needed, improving web performance and user experience by reducing initial load times and server load.

Higher-order functions in JavaScript enhance code conciseness, reusability, modularity, and performance through abstraction, common patterns, and optimization techniques.

The article discusses currying in JavaScript, a technique transforming multi-argument functions into single-argument function sequences. It explores currying's implementation, benefits like partial application, and practical uses, enhancing code read

The article explains React's reconciliation algorithm, which efficiently updates the DOM by comparing Virtual DOM trees. It discusses performance benefits, optimization techniques, and impacts on user experience.Character count: 159

Article discusses connecting React components to Redux store using connect(), explaining mapStateToProps, mapDispatchToProps, and performance impacts.

The article explains useContext in React, which simplifies state management by avoiding prop drilling. It discusses benefits like centralized state and performance improvements through reduced re-renders.

Article discusses preventing default behavior in event handlers using preventDefault() method, its benefits like enhanced user experience, and potential issues like accessibility concerns.


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 Chinese version
Chinese version, very easy to use

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.

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

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),