How to update html5 range on change of a text input?

前端 未结 6 1462
忘掉有多难
忘掉有多难 2021-02-07 13:59

I have a html5 range input and a text box input. When the range changes, the text box will get updated. But what should I do so that when I put a number in the text box, the ran

6条回答
  •  别跟我提以往
    2021-02-07 14:28

    in my side I did it in just Javascript and adding a onchange event.

    I also added the value=0 to range so that make it start at the beguining.

    ​​​​​​​

    var slider = document.getElementById('slider');
    var box = document.getElementById("box");
    
    slider.onchange = function(){
        box.value = slider.value;
    }
    

    And add this if you want to make it work on both side

    box.onkeyup = function(){
          slider.value = box.value;      
    } ​
    

提交回复
热议问题