我不熟悉JavaScript,并且一直在研究如何将范围滑块值存储到全局变量中。我尝试了多种方法来尝试显示全局变量值,但没有任何效果。附件是我的代码片段。
var slider01 = document.getElementById("textInput01").value;
var slider02 = document.getElementById("textInput02").value;
<div class="slidecontainer">
<b>Slider 1:</b><input type="range" name="rangeInput01" id="rangeInput01" step=".01" min="0" max=".1" onchange="textInput01.value=value">
Value: <output id="textInput01"></output><br />
<b>Slider 2:</b> <input type="range" name="rangeInput02" id="rangeInput02" step=".01" min="0" max=".1" onchange="textInput02.value=value">
Value: <output id="textInput02"></output><br />
</div>
This is where I'm testing <span id="slider01"></span><br/>
This is where I'm testing <span id="slider02"></span>
答案 0 :(得分:0)
您必须执行以下操作:
<b>Slider 1:</b><input type="range" name="rangeInput01" id="rangeInput01" step=".01" min="0" max=".1" onchange="setSpanValue('slider01', this.value)">
在JS中:
function setSpanValue(id, value){
document.getElementById(id).innerHTML = value;
}