W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>本例演示如何将 "onhashchange" 事件分配给 window 对象。</p> <p>点击按钮将当前网址的锚部分改为 #part5</p> <button onclick="changePart()">试一试</button> <p id="demo"></p> <script> // 使用 location.hash 属性更改锚点部分 function changePart() { location.hash = "part5"; var x = location.hash; document.getElementById("demo").innerHTML = "The anchor part is now: " + x; } window.onhashchange = myFunction; function myFunction() { alert("The anchor part has changed!"); } </script> </body> </html>