我想不通。我检查了有关设置数据属性的其他问题,这似乎是一件很棘手的事情。
Stripe 按钮数量纯粹是为了美观,我试图在每次用户更新数量选择框时设置它('data-amount')。
每次我更改数量选择时,警报都会给出正确的数量,如果我检查 dom,“数据量”属性似乎设置正确,但是当我单击 Stripe 按钮时,模态显示默认数据量,即什么都没有。
有人知道怎么做吗?
View (表单,未显示选择输入)
<div class="stripe-controls" align="center">
<script src="https://button.stripe.com/v1/button.js" class="stripe-button"
data-key="ENV['STRIPE_PUBLIC_KEY'] %>" data-amount="">
</script>
</div>
CoffeeScript
$ ->
$('#order_quantity').click(orderTotal)
orderTotal()
orderTotal = ->
quantity = $('#order_quantity').val()
price = $('#ticket-price').data('url')
total = quantity * price
$('.stripe-button').attr('data-amount', total)
alert total
最佳答案
使用 StripeCheckout.open()
指定自定义金额.
注意:我在 Stripe 工作。
关于javascript - 在 Stripe 按钮上设置数据属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12925734/