1: jQuery is a fast and simple JavaScript framework. The framework can be directly understood as encapsulating the original underlying things so that developers can use this framework to develop quickly.
2: Event bubbling is supported in every browser today. The so-called bubbling can be understood like this:
Conditions: There is a DIV element in the outer layer and a P element in the inner layer. There is such a relationship between them: DIV is the parent element of the P element, and P is the child element of the outer DIV. There is inclusion between them. and contained relationships.
Event: Now we bind the same event on both elements, such as click event.
Result: At this time, when we click the inner P tag, the click event of the inner element is triggered, and the click event of the outer DIV is also triggered.
3: Some elements in HTML are defined with some default attributes, such as the A element. This element is the hyperlink tag we usually use. The default attribute of this tag is to implement page jumps.
4: In every jQuery event, there will be a default object as a parameter of the event (but it must be specified explicitly). This object is the event object, which contains some properties and methods for different occasion. As follows:
$('p:first').click(function(event){
//event object can be used
});
5: Sometimes we don’t want to bubble or default event occurs, so you need some jQuery methods to prevent bubbling and default events. Different levels of blocking can be achieved through the following three methods.
A: return false --->In event handler, prevents default behavior and event bubbing.
Return false can prevent the default events and bubbling events in the incident.
B: event.preventDefault()---> In event handler, prevent default event (allows bubbling).
Event.preventDefault() can prevent default events but allow bubbling events to occur during event processing.
C: event.stopPropagation()---> In event handler, prevent bubbling (allows default behavior).
event.stopPropagation() can prevent bubbling during event processing. Bubble but allow default events to occur.
Code such as:
$('.menu li').click(function(){
$(this).find('ul').toggle();
return false;//Remove and try the effect })
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn