英文:
Making an event listener for a range slider from an html form
问题
document.getElementById("slider").onmouseup = function(){
newWord = letterShifter(document.getElementById("slider").value, document.getElementById("wordInput").value.toLowerCase());
document.getElementById("topcipher").innerText = newWord;
};
英文:
I have been trying to get this eventlistener for my range input to work onmouseup after the client has selected the number on the slider though it won't pick it up.
window.onload = function(){
document.getElementById("wordInput").onkeyup = function(){
sliderInt = parseInt(document.getElementById("slider").value);
newWord = letterShifter(sliderInt, this.value.toLowerCase());
document.getElementById("topcipher").innerText = newWord;
};
document.getElementById("slider").onmouseup = function(){
newWord = letterShifter(document.getElementById("slider").value, document.getElementById(wordInput).toLowerCase());
document.getElementById("topcipher").innerText = newWord;
};
The first wordInput eventlistener works (just takes a word from a text input) but the slider on mouse up one does not. What could I do to fix this please?
答案1
得分: 1
你没有发布完整的代码示例,但"onmouseup"事件在滑块上完美工作。
<input type="range" min="1" max="100" value="50" class="slider" id="slider">
<span id="topcipher"></span>
window.addEventListener("load", (event) => {
document.getElementById("slider").onmouseup = function() {
sliderInt = parseInt(document.getElementById("slider").value);
document.getElementById("topcipher").innerText = sliderInt;
};
});
英文:
You didn't post a full code example, but onmouseup event perfectly works on slider.
<input type="range" min="1" max="100" value="50" class="slider" id="slider">
<span id="topcipher"></span>
window.addEventListener("load", (event) => {
document.getElementById("slider").onmouseup = function() {
sliderInt = parseInt(document.getElementById("slider").value);
document.getElementById("topcipher").innerText = sliderInt;
};
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论