我有一个很好的Bootstrap定价滑块,最初来自这里:http://amirolahmad.github.io/bootstrap-pricing-slider/
在我的Bootstrap Pricing Slider中,我有"总金额"在完成所有数学计算之后,我得到了一个总分的分数。
我有"流程"按钮通常什么都不做,不会转发到任何地方。
当我得到总分并点击" Process"金额将复制到paypal支付,按钮将转发给paypal支付,并将包括显示在总分上的金额。我需要它用于mounthly和每年付款。
以下是整个代码:
<!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 :(得分:3)
您需要编辑update()
函数以将值写入PayPal表单。例如;
将此添加到底部附近的update()
函数中(在数学计算完成后)
$("#paypal_amount").val($amount);
然后添加PayPal表单
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions" />
<input type="hidden" name="business" value="MyEmailAddress@gmail.com" />
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="a3" value="" id="paypal_amount" />
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="D">
<input type="hidden" name="return" value="http://example.com/paypal-return" />
<input type="hidden" name="cancel_return" value="http://example.com/paypal-cancel" />
<input type="hidden" name="notify_url" value="http://example.com/paypal-notify" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="image" src="http://www.paypal.com/en_GB/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
http://jsfiddle.net/yk6fkh1s/2/
注意: Paypal确实有subscription and recurring payment documentation我建议您阅读。上面的表单将为 x 天创建订阅。