<body onhashchange="myFn()">
<a href="#123">123</a>
<a href="#456">456</a>
</body>
<script>
function myFn() {
console.log('good1230.com')
}
</script>
let textarea = document.querySelector('textarea')
textarea.onbeforeinput = function (e) {
let RegEx = /[0-9]/
if (RegEx.test(e.data)) {
e.returnValue = false
}
}
https://zh.javascript.info/fetch
async test() {
let response = await fetch('good4/test/1.jpg');
let blob = await response.blob(); // 下载为 Blob 对象
const progressBar_max = document.getElementById("progressBar_max");
progressBar_max.innerHTML = `${(blob.size / 1024 / 1024).toFixed(3)}MB`;
// 为其创建一个 <img>
let img = document.createElement('img');
img.style = 'width:100px';
document.body.append(img);
// 显示它
img.src = URL.createObjectURL(blob);
},
https://zinoui.com/blog/ajax-request-progress-bar
download() {
var progressBar = document.getElementById("progress");
var progressBar_value = document.getElementById("progressBar_value");
var progressBar_max = document.getElementById("progressBar_max");
var xhr = new XMLHttpRequest();
xhr.open("GET", "/good4/1.jpg?" + Math.floor(Math.random() * 99999), true);
xhr.responseType = "text";
xhr.onprogress = function (e) {
console.log(e)
if (e.lengthComputable) {
progressBar.max = e.total;
progressBar.value = e.loaded;
progressBar_value.innerHTML = `${(e.loaded / 1024 / 1024).toFixed(3)}MB`;
progressBar_max.innerHTML = `${(e.total / 1024 / 1024).toFixed(3)}MB`;
}
};
xhr.onloadstart = function (e) {
progressBar.value = 0;
};
xhr.onloadend = function (e) {
progressBar.value = e.loaded;
};
xhr.send(null);
}