input[type="range"]目标是当您将鼠标悬停在常规值上时,它会更改其值。
为此,我.mouseenter(function() {});通过 jQuery 使用了一个事件。
我附上现有的代码:
$('input[type="range"]').mouseenter( function() {
alert('Value = ' + $(this).val());
});
<input type="range" name="state" min="0" max="10" value="0" />
为什么单击时此代码会在 console.log 中输出过高的数量?!
var state = 0; // нужен для сохранения значения
$('input[type="range"]').on('mouseenter mousemove', function(e) {
$(this).val((e.pageX - $(this).offset().left) / ($(this).outerWidth() / 10));
console.clear(); console.log($(this).val());
$(this).on('click', function() {
state = $(this).val();
console.log(state);
});
});
随它吧: