在 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