Using href attribute for button element

前端 未结 4 1533
灰色年华
灰色年华 2021-01-27 23:01

I need that use href=\"\" attribute for button

like this Instead of

相关标签:
4条回答
  • 2021-01-27 23:18

    Try this. This will navigate to the link on click.

     <button onclick="window.location.href='http://www.stackoverflow.com'">click me</button>
    
    0 讨论(0)
  • 2021-01-27 23:18

    Why you don't use <a type="button" href=""></a>

    Or if you really want a button, so <button onclick="window.location.href=""></button>

    0 讨论(0)
  • 2021-01-27 23:37

    I think this will solve your problem

    <a href="http://www.stackoverflow.com/">
        <button>click me</button>
    </a>
    
    0 讨论(0)
  • 2021-01-27 23:41

    href attribute can not be used on button tag , if you want button like appearance for your a tag you can use add style to your a tag and make it look like button , add bootstrap reference then add button class to your anchor tag. Custom Bootstrap Button , but if you still want to use button tag then adding onclick event is better option

    0 讨论(0)
提交回复
热议问题