JavaScript三種方法跳轉網頁

JavaScript三種方法跳轉網頁

1、語法

  • window.location=‘你要轉向的頁面’"
  • window.location.href=‘你要轉向的頁面’
  • javascript:location.href=‘你要轉向的頁面’

2、使用

上述三條語句可用於HTML標籤的onclick事件:

<input type="button" value="跳轉" οnclick="window.location='你要轉向的頁面'">
<input type="button" value="跳轉" οnclick="window.location.href='你要轉向的頁面'">  
<input type="button" value="跳轉" οnclick="javascript:location.href='你要轉向的頁面'">

也可用於js文件中。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章