我正在尝试捕获表单上的提交按钮,并进行一些处理(在这种情况下,将信用卡数据发送到 Stripe)。我有一个 Order 类,当按下新的订单提交按钮时,它会捕获提交并将其发送到我的captureSubmitForStripe
方法。那部分工作得很好,这是一个代码片段:
# orders.js.coffee:
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
order.setupForm()
order =
setupForm: ->
$('#new_order').submit ->
order.captureSubmitForStripe()
captureSubmitForStripe: ->
# do more stuff here...
我也想让编辑表单上的提交按钮也能做到这一点。我该如何编写它,以便它从我所在的任何表单中捕获提交按钮,或者至少从新表单和编辑表单中捕获提交按钮?
我已经尝试过这个,除其他外,它不起作用:
order =
setupForm: ->
$('#new_order').submit ->
order.captureSubmitForStripe()
$('#edit_order').submit ->
order.captureSubmitForStripe()