我试图制作一个范围滑块,如果我用滑块选择一个值,它将显示一件事,如果我选择另一个值,它将显示另一件事。因此,我尝试使用开关盒:如果您的值是0-,请给我显示此消息;如果您的值是30,请给我显示另一条消息。问题是它根本不起作用…。在这里,我添加了我的代码:
!(https://postimg.cc/Lnd1PhSs)
所以我的HTML代码是这样的:
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
};
switch (output) {
case 0:
document.write("Good job<br />");
break;
case 30:
document.write("Pretty good<br />");
break;
case 60:
document.write("Passed<br />");
break;
case 90:
document.write("Passed<br />");
break;
default:
document.write("Unknown grade<br />");
}
document.write("Exiting switch block");
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 5px;
background: grey;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: rgb(58, 111, 46);
border-radius: 40px;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
background: rgb(58, 111, 46);
border-radius: 40px;
border: none;
}
<input type="range" min="0" max="90" value="0" step="30" class="slider" id="myRange">
<p>Value: <span id="demo"></span></p>
温温酱
胡子哥哥
叮当猫咪
相关分类