Sự miêu tả. Liên kết trình xử lý sự kiện với sự kiện JavaScript "nhấp chuột" hoặc kích hoạt sự kiện đó trên một phần tử
đã thêm phiên bản. 1. 0 . nhấp chuột [trình xử lý]
xử lý
Loại. Hàm[ Sự kiện eventObject ]
Một chức năng để thực thi mỗi khi sự kiện được kích hoạt
đã thêm phiên bản. 1. 4. 3 . nhấp chuột [ [eventData ], trình xử lý ]
dữ liệu sự kiện
Loại. Bất cứ điều gì
Một đối tượng chứa dữ liệu sẽ được chuyển đến trình xử lý sự kiện
xử lý
Loại. Hàm[ Sự kiện eventObject ]
Một chức năng để thực thi mỗi khi sự kiện được kích hoạt
đã thêm phiên bản. 1. 0 . nhấp []
Chữ ký này không chấp nhận bất kỳ đối số
Phương pháp này là một phím tắt cho .on[ "click", handler ]
trong hai biến thể đầu tiên và .trigger[ "click" ]
trong biến thể thứ ba. Sự kiện click
được gửi đến một phần tử khi con trỏ chuột ở trên phần tử đó và nhấn và thả nút chuột. Bất kỳ phần tử HTML nào cũng có thể nhận sự kiện này. Ví dụ, hãy xem xét HTML
1
2
3
4
5
6
, , , , ,
Click here
Trigger the handler
, , and . It means we cannot apply the title event on the given tags.
In HTML, we can use the title attribute and assign a JavaScript function to it. We can also use the JavaScript's addEventListener[] method and pass a click event to it for greater flexibility.
Syntax
Now, we see the syntax of using the title event in HTML and in javascript [without addEventListener[] method or by using the addEventListener[] method].
In HTML
In JavaScript
In JavaScript by using the addEventListener[] method
Let's see how to use title event by using some illustrations. Now, we will see the examples of using the title event in HTML, and in JavaScript.
Example1 - Using title attribute in HTML
In this example, we are using the HTML title attribute and assigning a JavaScript's function to it. When the user clicks the given button, the corresponding function will get executed, and an alert dialog box will be displayed on the screen.
Test it NowOutput
paragraph element, the corresponding function will get executed, and the text of the paragraph gets changed. On clicking the element, the background color, size, border, and color of the text will also get change. Test it NowOutput
Test it NowOutput
On clicking the text Click me, the output will be -