"01" A tag is only used as a button to set the HREF method

Source: Internet
Author: User

A tag is used as a button,
There are four ways to stop the event effect when handling JavaScript actions.

    • <a href="#">
    • <a href="javascript:;">
    • <a href="javascript:void(0)">
    • <a role="button" tabindex="0">

This can be considered in the following order.

    1. You can use the button tag, directly with the button tag. Recommended
    2. If you need to use a tag:<a href="javascript:;" role="button">
      • Click a tag before script load will not scroll to the page like href= "#".
      • javascript:void(0);same as the effect, but more simple
      • Role: Accessibility
      • tab focusing possible (by using HREF)
    3. If you need to delete href property: <a role="button" tabindex="0"> (cursor chart with CSS control)
      • If there is no href on a tag, you can't tab focusing.
      • But setting tabindex= "0" will focusable. (In tab order, follow the basic markup order)
      • Reference: If focus is forbidden, use ' tabindex= '-1 "
Reference <a href="#">Disadvantages
    • Not the original purpose of the hash (anchor is the mobile feature location is used)
    • Clicking on the words will scroll the bar to the page list. (column: script error before script load)
It is recommended to use the button tag if the tag is handled with JavaScript .#
    • It is recommended to use the HTML basic button <button>, <input type="button" /> <input type="image" /> . Better than using the button role property.
    • Https://developer.mozilla.org/ko/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_button_role
A tag to set the HREF method only for button use #

href="javascript:;"Orhref="javascript:void(0);"

    • Two of them are the same. (Stop the default effect of a tag)
    • Use JavaScript when you click Process
    • Click before script load will not href="#" scroll to the same page
void (0)? #
    • Https://stackoverflow.com/questions/7452341/what-does-void-0-mean

    • Https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/void
      void(0)Use for Generation undefined (void is to return undefined each time)

    • Reason: Undefined will be the override. (though ECMAScript 5 or newer is no problem ...) )

alert(undefined); //alerts "undefined"var undefined = "new value";alert(undefined) // alerts "new value"
    • Why is it 0? : Very simple, very idiomatic.
    • Many minifiers replace the undefined void 0 (small dosage, safe)
    • Reference: With void 0 the same meaning
<a role="button" tabindex="0">Way

http://wit.nts-corp.com/2014/04/14/1297 > "a Tag"
Https://stackoverflow.com/questions/10510191/valid-to-use-a-anchor-tag-without-href-attribute

You need to use a tag + delete href (no destination):

      1. Delete href Property
      2. The role property provided on the Wai-aria spec must tell the button
      3. For focusable Setuptabindex="0"
        • tab order, follow the basic markup sequence.
        • You can't tab the focus without href.

"01" A tag is only used as a button to set the HREF method

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.