The relationship between a tag and click

Source: Internet
Author: User

When you click on the browser a tag, the browser's default mechanism is as follows:

1. Trigger A's Click event
2. Read the value of the href attribute
3, if it is a URI jump
4. If it is JavaScript code, execute the code

Let's do an experiment together:

We write the following code in an HTML page:

1
<a href="http://www.baidu.com" id="A" > This is a label </a>

The code has only one a tag, and then we use JS respectively to trigger Touchstart, Touchend, MouseDown, MouseUp, click events, test what can be a tag jump of all the events, our JS code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
Event array
var events =' Touchstart touchend mousedown mouseup click '. Split (‘ ‘);
var n = 0;
//turn on timer, every two seconds for a tag trigger corresponding event
var timer = setinterval (function ( var event = new event (Events[n]);
document.getelementbyid (//trigger event.
console.log (event.type);
n++;
if (n = = events.length) {
Clearinterval (timer);
},2000);

We can see that in the console every two seconds will print out the current event triggered by a tag, when the last click event triggered, a tag to perform a jump, jump to Baidu, which also shows that a tag jump only click event can trigger, so when clicking a tag, make a request, The browser will first trigger the Click event of a, and we all know that the Click event will have a 300 millisecond delay on the mobile side, so this is why the list on the home page is slow to click, and I've always thought that the A-tag's jump is not related to the Click event. Why am I so low?????????

So finally: When you develop the mobile page, do not feel that you do not show to an element to bind the Click event there will be no 300 millisecond delay problem, in fact a tag jump will also trigger the Click event, if not processed, there will be 300 milliseconds delay problem, This is extremely bad for the user experience.

From http://hcysun.me/2015/11/26/a%E6%A0%87%E7%AD%BE%E7%9A%84href%E5%B1%9E%E6%80%A7%E4%B8%8Eclick%E4%BA%8B%E4%BB% b6%e7%9a%84%e7%83%a6%e6%81%bc/#more

The relationship between a tag and click

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.