在HTML中调用来自不同文件的JS函数

时间:2022-03-17 06:28:23

I am trying to have an html slider call a javascript function from another file. I have this for my html:

我试图让html滑块从另一个文件调用javascript函数。我有这个为我的HTML:

    <input type="range" min="0" max="20*Math.PI" value="10" id="angularVelCarousel" onChange="changeValCarousel(this.value)"/>
    <span id="valueCarousel">10</span>
    <script src='slider.js'></script>

and this for my js (in a file called slider.js)

这对我的js(在一个名为slider.js的文件中)

function changeValCarousel(value){

    document.getElementById('valueCarousel').innerHTML = value;


}

how can I make it so that when the slider changes, it executes the js file above? Thanks!

如何使滑块更改时,它执行上面的js文件?谢谢!

1 个解决方案

#1


0  

Maybe something like this:

也许是这样的:

function changeValCarousel(value){
    document.getElementById('valueCarousel').innerHTML = value;
}

var slider = document.getElementById('angularVelCarousel');
slider.onchange=function(){changeValCarousel(slider.value)};

Full code here https://jsfiddle.net/ta434v5p/

完整代码在这里https://jsfiddle.net/ta434v5p/

#1


0  

Maybe something like this:

也许是这样的:

function changeValCarousel(value){
    document.getElementById('valueCarousel').innerHTML = value;
}

var slider = document.getElementById('angularVelCarousel');
slider.onchange=function(){changeValCarousel(slider.value)};

Full code here https://jsfiddle.net/ta434v5p/

完整代码在这里https://jsfiddle.net/ta434v5p/