# 表單元素聚焦
網頁打開時,光標聚焦在當前表單。
```
<input type="text" id="input">
<script>
document.getElementById('input').focus()
</script>
```
# onhashchange事件
onhashchange 事件在當前 URL 的錨部分(以 '#' 號為開始) 發生改變時觸發 。
錨部分的實例:指定當前 URL 為[http://www.example.com/test.htm#part2](http://www.example.com/test.htm#part2) - 這個 URL 中的錨部分為 #part2。
你可以使用以下方式調用事件:
* 通過設置[Location 對象](https://www.runoob.com/jsref/obj-location.html)的[location.hash](https://www.runoob.com/jsref/prop-loc-hash.html)或[location.href](https://www.runoob.com/jsref/prop-loc-href.html)屬性修改錨部分。
* 使用不同書簽導航到當前頁面(使用"后退" 或"前進"按鈕)
* 點擊鏈接跳轉到書簽錨
*****
## 瀏覽器支持
表格中的數字表示支持該事件的第一個瀏覽器的版本號。
| 事件 | chrome | IE | Firefox | Sarifi | Opera |
| --- | --- | --- | --- | --- | --- |
| onhashchange | 5.0 | 8.0 | 3.6 | 5.0 | 10.6 |
## 案例
```
<a href="#box1">跳</a>
<a href="#box2">跳</a>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br>
<script>
// hash不會引起瀏覽器發生跳轉
//路由就是管理瀏覽器鏈接的 可以通過hash來進行管理路由
window.onhashchange = function(){
console.log(location.hash)
}
</script>
```