HTML5 Slider with onchange function

后端 未结 1 532
攒了一身酷
攒了一身酷 2020-12-19 02:37

I have a slider (input type range) that is supposed to run a function when the value is being changed. The function should then display the new value in a seperate div-conta

1条回答
  •  眼角桃花
    2020-12-19 03:19

    It works, you just need to make sure that the javascript function is defined when the element is rendered, f.ex.

    
    
    

    See this demo: http://jsfiddle.net/Mmgxg/

    A better way would be to remove the inline onchange attribute:

    
    

    And then add the listener in your javascript:

    var slide = document.getElementById('slide'),
        sliderDiv = document.getElementById("sliderAmount");
    
    slide.onchange = function() {
        sliderDiv.innerHTML = this.value;
    }​
    

    ​http://jsfiddle.net/PPBUJ/

    0 讨论(0)
提交回复
热议问题