运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body onhashchange="myFunction()"> <p>Click the button to change the anchor part of the current URL to #part5</p> <button onclick="changePart()">Try it</button> <p id="demo"></p> <script> // Using the location.hash property to change the anchor part function changePart() { location.hash = "part5"; let x = "The anchor part is now: " + location.hash; document.getElementById("demo").innerHTML = x; } // Alert some text if there has been changes to the anchor part function myFunction() { alert("The anchor part has changed!"); } </script> </body> </html>