JS block Element (document) default event, block bubbling event __js

Source: Internet
Author: User

1. Block the default event for a form, or the default event "Event.preventdefault ()" That slides in the HTML5 Chinese file, blocking the default event for the element.

Demo1-1: Block element class default event

<a href= "http://www.baidu.com" target= "_black" > Baidu </a>

Document.getelementbytagname ("a"). AddEventListener ("click", Function (e) {e.preventdefault ()},false);

Click on the link when the normal will occur jump, but now we have blocked its default event, that is, jump events, then will not jump to Baidu.


DEMO1-2: Block document default event in Mobile end

Document.ontouchmove = function (EV) {
Ev.preventdefault ();
};

=========


2 、--block element bubbling event "(ie:) ev.cancelbubble = true; (ff:) ev.stoppropagation (); 】;

Demo

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.