是的,您可以使用 html5 元素和 jQuery 来实现,如下所示:
http://jsfiddle.net/sRbHZ/
HTML:
<input type="text" name="chance" id="chance" class="text" value="50">
<input type="range" id="chance_slider" class="vHorizon" min="0.01" max="98" style="background-color: #00aec8; width: 50%;">
JS:
var slider = $('#chance_slider'),
textbox = $('#chance');
slider.change(function() {
var newValue = parseInt($(this).val());
textbox.val(newValue);
});
textbox.change(function() {
var newValue = parseInt($(this).val());
slider.val(newValue);
});
编辑
允许小数:
var slider = $('#chance_slider'),
textbox = $('#chance');
slider.change(function() {
var newValue = $(this).val();
textbox.val(newValue);
});
textbox.change(function() {
var newValue = $(this).val();
slider.val(newValue);
});