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);
}
// If the achor part is changed
function newFunc() {
alert("Anchor part changed!");
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP