fillword.js & highlight.js: fix JavaScript errors on the front page

Bug536-Jiangwangzhe
Lan Hui 2024-08-30 08:32:09 +08:00
parent 0c6616d52c
commit e6c945bac7
2 changed files with 17 additions and 10 deletions

View File

@ -21,14 +21,19 @@ function fillInWord() {
localStorage.setItem('selectedWords', element.value);
}
document.getElementById("text-content").addEventListener("click", fillInWord, false);
if (document.getElementById("text-content")) {
document.getElementById("text-content").addEventListener("click", fillInWord, false);
}
const sliderValue = document.getElementById("rangeValue");
const inputSlider = document.getElementById("rangeComponent");
inputSlider.oninput = () => {
let value = inputSlider.value;
sliderValue.textContent = value + '×';
};
if (inputSlider) {
inputSlider.oninput = () => {
let value = inputSlider.value;
sliderValue.textContent = value + '×';
};
}
function onReadClick() {
isRead = !isRead;

View File

@ -9,11 +9,13 @@ function cancelBtnHandler() {
}
function showBtnHandler() {
document.getElementById("text-content").removeEventListener("click", fillInWord2, false);
document.getElementById("text-content").removeEventListener("touchstart", fillInWord2, false);
document.getElementById("text-content").addEventListener("click", fillInWord, false);
document.getElementById("text-content").addEventListener("touchstart", fillInWord, false);
highLight();
if (document.getElementById("text-content")) {
document.getElementById("text-content").removeEventListener("click", fillInWord2, false);
document.getElementById("text-content").removeEventListener("touchstart", fillInWord2, false);
document.getElementById("text-content").addEventListener("click", fillInWord, false);
document.getElementById("text-content").addEventListener("touchstart", fillInWord, false);
highLight();
}
}
function replaceWords(str, word) {
let count = 0;