Chào mừng bạn quay lại với chuỗi bài học jQuery trên CodeTutHub! Ở bài trước, chúng ta đã làm quen với cách thao tác chọn phần tử bằng jQuery. Hôm nay, chúng ta sẽ tìm hiểu một trong những phần quan trọng nhất của jQuery: Events - Sự kiện.
1. jQuery Event là gì?
Trong JavaScript nói chung và jQuery nói riêng, event (sự kiện) là những hành động mà người dùng hoặc trình duyệt thực hiện, như click chuột, di chuột, nhập liệu, cuộn trang, v.v.
jQuery giúp bạn xử lý các sự kiện này một cách ngắn gọn và dễ hiểu hơn nhiều so với JavaScript thuần.
2. Cấu trúc xử lý sự kiện trong jQuery
Cú pháp cơ bản:
$(selector).event(function() {
// hành động khi sự kiện xảy ra
});Ví dụ:
Learn Python syntax easily with this beginner-friendly guide. Understand basic syntax rules, variables, loops,...
Struggling with the “Key is already in use” error when adding an SSH key to GitHub? This guide walks you through the...
Learn how to get URL segments in Laravel using Request::segment() and segments() methods. Step-by-step examples and best...
Struggling with the “Key is already in use” error when adding an SSH key to GitHub? This guide walks you through the...
Learn how to clear cache in Laravel 12 for Routes, Views, Config, Events, and more. Detailed guide on Artisan commands...
Learn how to install Python quickly and easily with this step-by-step guide for Windows, macOS, and Linux. Start your...
Learn Python syntax easily with this beginner-friendly guide. Understand basic syntax rules, variables, loops,...
Learn how to use CSS offset-path, offset-position, offset-distance, and offset-rotate properties to create smooth and...
