是玩,你可以用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);
});
ID應該是唯一的所有元素。 – Puuskis
ID必須是唯一的,所以你不能在一個頁面上放置2個或更多相同的ID。 –