How to create an HTML button that acts like a link?

后端 未结 30 3607
长发绾君心
长发绾君心 2020-11-21 04:18

I would like to create an HTML button that acts like a link. So, when you click the button, it redirects to a page. I would like it to be as accessible as possible.

30条回答
  •  耶瑟儿~
    2020-11-21 04:58

    As of HTML5, buttons support the formaction attribute. Best of all, no Javascript or trickery is needed.

    Caveats

    • Must be surrounded by
      tags.
    • Overrides the default action in a form. In other words, if you do this inside another form it's going to cause a conflict.

    Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-formaction Browser Support: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Browser_compatibility

提交回复
热议问题