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文件中。