a tag's href and click event

<a href='index.html' onclick='index()' >链接</a>

If there are both href and onclick in the a tag, the above writing method, onclick is executed first, href is executed after (page jump), but when there may be href jump, the click event handler has not yet taken effect;

Methods to prohibit href execution:

(1) href='javascript:void(0)', only the onclick event is executed at this time, it is recommended to use it when the href is not linked;

(2) onclick execution, returns false, href does not execute;

But we often use href = '#' to abbreviate empty links, click a link, '#' will be appended to the end of the url; and the page will be at the top;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324911004&siteId=291194637