Firefox onchange Event Not Triggered on Range Input Drag
In input elements with type "range," when the slider is dragged, the onchange event is only triggered when the slider is dropped to a new position in Firefox. In contrast, Chrome and other browsers trigger onchange events during the drag.
Solution: Use oninput Event
Firefox correctly triggers the onchange event only upon release, as per the specification. To capture live updates during dragging in all browsers, use the oninput event instead.
function showVal(newVal){
document.getElementById("valBox").innerHTML=newVal;
}
Combining oninput and onchange for Cross-Browser Compatibility
For cross-browser compatibility, consider combining both oninput and onchange event handlers:
This ensures that onchange events are still triggered in Firefox upon release, while oninput events provide continuous updates in all browsers.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3