我有一个很好的bootstrap定价滑块,最初来自这里:http://amirolahmad.github.io/bootstrap-pricing-slider/
奇怪的是 - 价值改变了显示的相同数字。例如:
如果我在第一个滑块选择100 并在第二个滑块上选择1,我将得到 100 。
如果我在第二个滑块上选择2,我将获得 200 。等等。
我想更改第一个滑块代码的值,所以当我在第一个滑块选择100而第二个滑块选择1时,它会在总数上给我 10 100。
以下是代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Pricing Slider</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<div class="container">
<div class="price-box">
<form class="form-horizontal form-pricing" role="form">
<div class="price-slider">
<h4 class="great">Amount</h4>
<span>Minimum $10 is required</span>
<div class="col-sm-12">
<div id="slider"></div>
</div>
</div>
<div class="price-slider">
<h4 class="great">Duration</h4>
<span>Minimum 1 day is required</span>
<div class="col-sm-12">
<div id="slider2"></div>
</div>
</div>
<div class="price-form">
<div class="form-group">
<label for="amount" class="col-sm-6 control-label">Amount ($): </label>
<span class="help-text">Please choose your amount</span>
<div class="col-sm-6">
<input type="hidden" id="amount" class="form-control">
<p class="price lead" id="amount-label"></p>
<span class="price">.00</span>
</div>
</div>
<div class="form-group">
<label for="duration" class="col-sm-6 control-label">Duration: </label>
<span class="help-text">Choose your commitment</span>
<div class="col-sm-6">
<input type="hidden" id="duration" class="form-control">
<p class="price lead" id="duration-label"></p>
<span class="price">days</span>
</div>
</div>
<hr class="style">
<div class="form-group total">
<label for="total" class="col-sm-6 control-label"><strong>Total: </strong></label>
<span class="help-text">(Amount * Days)</span>
<div class="col-sm-6">
<input type="hidden" id="total" class="form-control">
<p class="price lead" id="total-label"></p>
<span class="price">.00</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" class="btn btn-primary btn-lg btn-block">Proceed <span class="glyphicon glyphicon-chevron-right pull-right" style="padding-right: 10px;"></span></button>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<img src="images/payment.png" class="img-responsive payment" />
</div>
</div>
</form>
<p class="text-center" style="padding-top:10px;font-size:12px;color:#2c3e50;font-style:italic;">Created by <a href="https://twitter.com/AmirolAhmad" target="_blank">AmirolAhmad</a></p>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
$("#slider").slider({
range: "min",
animate: true,
value:1,
min: 10,
max: 1000,
step: 10,
slide: function(event, ui) {
update(1,ui.value); //changed
}
});
$("#slider2").slider({
range: "min",
animate: true,
value:1,
min: 1,
max: 365,
step: 1,
slide: function(event, ui) {
update(2,ui.value); //changed
}
});
//Added, set initial value.
$("#amount").val(0);
$("#duration").val(0);
$("#amount-label").text(0);
$("#duration-label").text(0);
update();
});
//changed. now with parameter
function update(slider,val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $amount = slider == 1?val:$("#amount").val();
var $duration = slider == 2?val:$("#duration").val();
/* commented
$amount = $( "#slider" ).slider( "value" );
$duration = $( "#slider2" ).slider( "value" );
*/
$total = "$" + ($amount * $duration);
$( "#amount" ).val($amount);
$( "#amount-label" ).text($amount);
$( "#duration" ).val($duration);
$( "#duration-label" ).text($duration);
$( "#total" ).val($total);
$( "#total-label" ).text($total);
$('#slider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$amount+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
$('#slider2 a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> '+$duration+' <span class="glyphicon glyphicon-chevron-right"></span></label>');
}
</script>
</body>
</html>
答案 0 :(得分:0)
$total = "$" + ($amount * ($duration * 0.1));
? (假设$ duration是你说的第二个滑块)
完美的工作答案是:
$total = "$" + ($amount * $duration * 0.1);