我有这个代码:MyFiddle
HMTL
<p>Money: <span id="amountDisp">500</span><div id="amount_slider"></div></p><p>Time: <span id="timeDisp">7</span><div id="time_slider"></div></p><p>Calculated <span id="result" >545</span></p>
查询:
$(document).ready(function () {
$("#amount_slider").slider({
orientation: "horizontal",
range: false,
min: 500,
max: 4999,
value: 500,
step: 1,
animate: true,
change: function (event, ui) {
$("#amount_field").val(ui.value);
$("#amount").text(ui.value);
calculate();
},
slide: function (event, ui) {
$("#amount_field").val(ui.value);
$("#amountDisp").text(ui.value);
}
});
$("#time_slider").slider({
orientation: "horizontal",
range: false,
min: 7,
max: 28,
step: 7,
value: 7,
animate: true,
change: function (event, ui) {
$("#time_field").val(ui.value);
$("#time").text(ui.value);
calculate();
},
slide: function (event, ui) {
$("#time_field").val(ui.value);
$("#timeDisp").text(ui.value);
}
});
function calculate() {
var amount = parseInt($("#amount_slider").slider("value"));
var time = parseInt($("#time_slider").slider("value"));
var coeficient = 0;
switch(time){
case 7: coeficient = 0.09;break;
case 14: coeficient = 0.15;break;
case 21: coeficient = 0.19;break;
case 28: coeficient = 0.25;break;
}
var rate = amount + (amount * coeficient);
$("#result").text(rate.toFixed(2));
$("#result_field").val(rate.toFixed(2));
}
});
1)它基本上做我想要的。但是,我想让“计算”字段(或输出)更平滑。所以它会在我滑动时改变它的价值。就像滑块上方的其他两个输出一样。
2)另一个问题是,如何为 . 我的意思是输入将由用户在典型的表单输入中输入。它也会计算。