[英]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:我通过侦听所有
mouseup
和touchend
事件找到了解决方法,然后过滤以仅对发生在 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.