Setting button hyperlinks in HTML pages

方法1:<a>标签 

    <a class="btn" href="http://www.baidu.com" target="_blank">新页面打开百度</a>
 
    <a class="btn" href="http://www.baidu.com">当前页面打开百度</a>

Method 2: <button> button

     < button  class = "btn"  onclick = "window.location.href='http://www.baidu.com'" >当前页面打开百度</ button >
 
     < button  class = "btn"  onclick = "window.open('http://www.baidu.com')" >新页面打开百度</ button >   

Comparison of advantages and disadvantages:

  The advantage of the a tag is that it is more convenient to write the URL (less words need to be typed~), it has its own hand-shaped mouse pointer, and no background. If you want to change it to open from a new page, just add a target="_blank" attribute. The disadvantage is that this is a fake button, the a tag rarely specifies events, and submitting forms is not commonly used. In addition, if you want to make it realistic, you need to add a lot of CSS styles, and you need to specify a class every time you make such a button, so the production efficiency is relatively low.

  The button itself does not have a hand pointer. If necessary, add cursor: pointer; this style, and it has its own background. If you don't want it, you need to set the style. In addition, the code for opening a webpage from the current page and opening a webpage from a new page is different. If you want to switch the opening method, you need to change the parentheses and quotation marks.

Generally, if you need to submit a form or something, use a button, and just use a tag to make a style for a simple page jump.

Guess you like

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