为什么在使用箭头键时,打开更改功能不适用于我的范围滑块

Why is the on change function not working for my range slider when using arrow keys?

本文关键字:不适用 功能 适用于 我的 范围 为什么      更新时间:2024-01-07

我在html和javascript 中的范围滑块有问题

<input type="range" name="slider-1" id="slider" value="60" min="0"   max="100">

它显示正确,在我单击它后和拖动滑块时使用箭头键移动。问题是,当我使用箭头键时,该功能不会启动,只有当我用鼠标拖动滑块时:

$('#slider').on('change',function() {
var x = $(this).val();
   document.getElementById('button').innerHTML = x + "px";
    document.getElementById('button').style.fontSize = x + "px";
console.log(x);});

以下是我的jsfiddle链接:http://jsfiddle.net/LbLw81oa/1/

我也一直在网上找,但没有找到任何关于这个话题的东西。我发现的唯一类似的东西是这个网站:http://api.jquerymobile.com/slider/,但他们使用的jquery版本破坏了我其他工作代码中的许多函数。感谢您抽出时间,任何意见都会有所帮助。

在你的小提琴中,你的小提琴第3行有一个额外的.style。然后按键启动功能(在Chrome中测试)一次。样式被删除。

 document.getElementById('button').innerHTML = x + "px";

更新Fiddle。