I have defined these sliders in the HTML file:
<div>
body angle -180 <input id="bodySlider" type="range"
min="-180" max="180" step="10" value="0"
/>
180
</div>
<div id="leftArmSlider">
left arm angle -90 <input id="leftArmSlider" type="range"
min="-90" max="-20" step="10" value="-20"
/>
-20
</div>
</div>
<div id="rightArmSlider">
right arm angle 20 <input id="rightArmSlider" type="range"
min="20" max="90" step="10" value="20"
/>
90
</div>
<div>
left leg angle -30 <input id="leftLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<div>
right leg angle -30 <input id="rightLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
and I wanna reset them to the initial values using a function in the JavaScript file. Is there a reset function or another way to do this?
I have defined these sliders in the HTML file:
<div>
body angle -180 <input id="bodySlider" type="range"
min="-180" max="180" step="10" value="0"
/>
180
</div>
<div id="leftArmSlider">
left arm angle -90 <input id="leftArmSlider" type="range"
min="-90" max="-20" step="10" value="-20"
/>
-20
</div>
</div>
<div id="rightArmSlider">
right arm angle 20 <input id="rightArmSlider" type="range"
min="20" max="90" step="10" value="20"
/>
90
</div>
<div>
left leg angle -30 <input id="leftLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<div>
right leg angle -30 <input id="rightLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
and I wanna reset them to the initial values using a function in the JavaScript file. Is there a reset function or another way to do this?
Share Improve this question edited May 22, 2017 at 15:00 user128511 asked May 22, 2017 at 13:34 B.juniorB.junior 351 gold badge2 silver badges12 bronze badges2 Answers
Reset to default 2add a button for the reset.
<input id="reset" type="button" value="Reset">
and this is the reset function
document.getElementById('reset').onclick = function(){
document.getElementById('bodySlider').value = 0;
document.getElementById('leftArmSlider').value = -20;
// .... etc
};
Be sure to not assign the same id on different HMTL element, id is thought to be unique.
another way is to wrap all the inputs inside a form and to reset the form
<form id="myForm">
<div>
body angle -180 <input id="bodySlider" type="range"
min="-180" max="180" step="10" value="0"
/>
180
</div>
<div>
left arm angle -90 <input id="leftArmSlider" type="range"
min="-90" max="-20" step="10" value="-20"
/>
-20
</div>
</div>
<div id="rightArmSlider">
right arm angle 20 <input id="rightArmSlider" type="range"
min="20" max="90" step="10" value="20"
/>
90
</div>
<div>
left leg angle -30 <input id="leftLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<div>
right leg angle -30 <input id="rightLegSlider" type="range"
min="-30" max="30" step="5" value="0"
/>
30
</div>
<input onclick="resetFunc()" type="button" value="Reset">
</form>
<script>
function resetFunc(){
document.getElementById("myForm").reset();
}
</script>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744793650a4594073.html
评论列表(0条)