简体   繁体   English

当 slider 值与初始值相同时,如何触发 html 输入类型 = 范围的更改事件

[英]How to fire a change event for html input type=range when slider value is same as initial value

I have an html input type=range slider like this:我有一个 html 输入类型=范围 slider 像这样:

<input type="range" min="0" max="5" step="0.1" value="0" class="slider" id="aroma-slider" (input)="trackInput($event, 'aroma')" (change)="slideDone($event, 'aroma')">

My events are firing great EXCEPT if the user drags the slider all the way down to 0, then the change event is not fired, even though the user has interacted with the slider and moved it.我的事件触发得很好,除非用户将 slider 一直拖到 0,然后change事件不会被触发,即使用户已经与 slider 交互并移动了它。 I assume it is because the slider value is the same as the original slider value in the value attribute.我认为这是因为 slider 值与value属性中的原始 slider 值相同。 How do I trigger a change event when the starting value and ending value of the slider happen to be the same?当 slider 的起始值和结束值恰好相同时,如何触发更改事件? In my use case the user selecting a 0 value is valid.在我的用例中,用户选择0值是有效的。

I figured out a work-around by listening to all mouseup and touchend events, then filtering to only act on the ones that happen on the slider:我通过侦听所有mouseuptouchend事件找到了解决方法,然后过滤以仅对发生在 slider 上的事件采取行动:

<input type="range" min="0" max="5" step="0.1" value="0" class="slider" id="aroma-slider" (input)="trackInput($event, 'aroma')" (change)="slideDone($event, 'aroma')">

$(document).on('mouseup touchend', (e:Event)=> {
    if ( $(e.target).attr('class') == 'slider' &&  $(e.target).val() == 0 ) {
        this.slideDone(e, 'aroma');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在用户释放范围滑块时触发“更改”事件,即使该值未更改 - How to fire a “change” event when the user releases the range slider, even if the value hasn't changed 带有负值的 HTML 输入类型范围(滑块) - HTML input type range (slider) with negative value 以编程方式更改输入值时如何触发 JQuery 更改事件? - How to fire JQuery change event when input value changed programmatically? 如何使用按钮更改 HTML 范围滑块值? - How to change HTML range slider value with button? 输入类型范围与 slider 上的值 - Input type range with value on slider 在HTML中显示当前滑块值(输入类型=“范围”) - Display current slider value (input type = “range”) in HTML 如何在鼠标按下事件时更改类型复选框的HTML输入的值 - How to change the value of HTML input of type checkbox on mouse down event 以编程方式更新输入值时发生火灾更改事件 - Fire change event when programmatically update input value 当我在呈现视图后设置该输入类型的值时,为什么不会触发输入类型的更改事件? - Why wouldn't the change event of a input type fire when I'm setting the value of that input type after the view is rendered? 没有为多个输入范围选择相同的值 slider - No same value picked for multiple input range slider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM