当用户更改JQuery范围控件上的值时,我希望更新一个值。我试着效仿给定的here,但是它不起作用。
$(document).ready(function () {
alert('ready1'); //This fires when the page loads.
// Logs the value while the user is moving the slider
$('.price-min').on('input', getValue);
function getValue(e) { //This never fires
var val = $(e.element).val();
alert(val);
}
});
HTML:
<div data-role="rangeslider">
<input type="range" name="price-min" id="price-min" value="200" min="0" max="1000">
<input type="range" name="price-max" id="price-max" value="800" min="0" max="1000">
</div>
有人能告诉我哪里出了问题吗?
发布于 2017-10-16 21:54:59
用你的代码做几件事。
$('.price-min')
)选择一个元素,但是您的范围有一个ID ($('#price-min)'
)。change
事件。
$(document).ready(function () {
function getValue(e) { // now this fires on range change event
var val = $(this).val();
console.log(val);
}
// Logs the value while the user is moving the slider
$('#price-min').on('change', getValue);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-role="rangeslider">
<input type="range" name="price-min" id="price-min" value="200" min="0" max="1000">
<input type="range" name="price-max" id="price-max" value="800" min="0" max="1000">
</div>
发布于 2017-10-16 21:57:39
您使用的是类选择器:
.price-min
而不是id选择器:
#price-min
您还需要得到这个而不是e.element
$(document).ready(function () {
alert('ready1'); //This fires when the page loads.
// Logs the value while the user is moving the slider
$('#price-min').on('input', getValue);
function getValue(e) {
var val = $(this).val();
alert(val);
}
});
https://stackoverflow.com/questions/46779639
复制相似问题