【问题标题】:Get the current value of a Slider via Javascript and store it in a variable通过 Javascript 获取 Slider 的当前值并将其存储在变量中
【发布时间】:2022-11-21 00:39:57
【问题描述】:

我基本上想制作一个网页,以范围滑块的速度改变背景颜色。 这是我的代码:

HTML:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">   
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<title>Color Change</title>
</head>
<body id="colo">
<input id="speed" type="range" min="10" max="10000" step="1.0" value="1000" oninput="this.nextElementSibling.value = this.value" >
<output id="output">1000</output>
</body>
</html>

CSS:

body {
background-color: #DBF9FC;
}

记者:

let i = 0;
function colorchange() {
    let doc = document.getElementById("colo");
    let color = ["yellow", "blue", "red", "green", "orange","pink","lightblue","purple"];
    doc.style.backgroundColor = color[i];
    i = (i + 1) % color.length;
}

intervall=1000;
setInterval(colorchange,intervall); 

变量 interval 应该从滑块范围中获取值,但我没有得到任何有效的解决方案。如果有人可以提供帮助,我会很高兴。谢谢。

【问题讨论】:

    标签: javascript slider getelementbyid


    【解决方案1】:

    IIRC 你可以使用document.getElementById(“speed”).value

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多