我有以下代码,我正在使用它来基于滑块值计算服务的价格。事件更改时Jquery滑块更新值
它运作良好,除了PriceVal不实时更新。只有当用户从滑块上点击鼠标时它才会更新。
有谁知道我可以如何在滑块滑动时实时更新它?
页可以在http://www.voxlogic.net/pricing/
$(function() {
//document.getElementById("f1").reset();
$(":range").rangeinput({ progress: true, max: 100, value:1 });
$(":range").change(function(){
var sliderVal = this.value;
calculatePrice(sliderVal);
});
$(":range").keyup(function(){
var sliderVal = this.value;
if (sliderVal==""){
$("#priceVal").html('');
}
else
{
//check if value is from 1..25 range and correct otherwise
if (isNaN(sliderVal)){sliderVal=1;}
if (sliderVal<1){sliderVal=1;}
if (sliderVal>25){sliderVal=25;}
this.value = sliderVal;
calculatePrice(sliderVal);
}
});
$(":range").keydown(function(){
var sliderVal = this.value;
calculatePrice(sliderVal);
});
});
function calculatePrice(sliderVal){
if (isNaN(sliderVal)){sliderVal=1;}
if (sliderVal<1){sliderVal=1;}
if (sliderVal>25){sliderVal=25;}
var priceVal;
if (sliderVal<=9){
priceVal = sliderVal*6;
}
else if ((sliderVal>9)&&(sliderVal<=19)){
priceVal = 9 * 6 + (sliderVal-9) * 4.5;
}
else if (sliderVal>19){
priceVal = 9 * 6 + 10 * 4.5 + (sliderVal-19) * 3.6;
}
$("#priceVal").html('£'+priceVal.toFixed(2));
}
});
可能的复制http://stackoverflow.com/questions/7523864/ui-slider-with-text-box-input – Gandalf
不是重复 – Alexander