JavaScript中onhashchange事件的用途是什么?
更改锚零件时,将发生onhashchange事件。您可以尝试运行以下代码,以了解如何在JavaScript中实现onhashchange事件。
示例
<!DOCTYPE html> <html> <body onhashchange="newFunc"> <button onclick="functionChange()">Click to change anchor</button> <script> function functionChange() { location.hash = "about"; var hash = location.hash; document.write("The anchor part is now: " + hash); } //如果脚部改变 function newFunc() { alert("锚部分已更改!"); } </script> </body> </html>