寻找某种解决方案,当拖动滑块时,它会从总量中取出值。现在它只是在你向后移动滑块时没有添加。 jsfiddle
function slider1(){
$( "#slider1h1" ).slider({
orientation: "horizontal",
range: "min",
value: 0,
min: 0,
max: 3500000,
step: 50,
slide: function( event, ui ) {
$( "#sliderVal" ).val( ui.value );//shows slider value
var Asset1 = $('#totalVal').val() - $('#sliderVal').val();
$('#totalVal').val(Asset1);//shows the total amount
}
});
$( "#sliderVal" ).val( $( "#slider1h1" ).slider( "value" ) );
};
<小时/> 来自DEMO:
HTML:
Amount<input type="text" id="amount" value="35000" /><br/><br/><br/>
<br/>
<div class="sliderNew"></div>
Food<input type="text" id="food" value="100" /><br/><br/><br/>
<br/>
Total<input type="text" id="total" />
JAVASCRIPT:
$(".slider").slider({
min: 0,
max: 35000,
slide: function(event, ui) { // Rule Calculation
$( "#amount" ).val( ui.value );
var Asset = $('#amount').val() - $('#total').val();
$("#total").val(Asset);
}
});
$(".sliderNew").slider({
min: 0,
max: 100,
value:0,
slide: function(event, ui) { // Rule Calculation
$( "#food" ).val( ui.value );
var foodVal = $( "#food" ).val();
if(foodVal != 0){
var food1 = $('#total').val() - (10*foodVal);
$('#total').val(food1);
}
}
});