0
我試圖配置一個coffeescript類來管理分段付款。我正在基於this tutorial的解決方案。Uncaught TypeError:Object#<HTMLInputElement> has no method'processCard'
這裏是我的代碼:
class Subscription
count = 0
page =
createForm: "form#new_subscription"
createButton: 'input#create_subscription[type=submit]'
cardNumber: '#card_number'
cardCode: '#card_code'
cardMonth: '#card_month'
cardYear: '#card_year'
stripeError: '#stripe_error'
setupForm: ->
console.log "binding to submit"
$(page.createButton).click (e) ->
$(page.createButton).attr('disabled', true)
@processCard()
return false
processCard: ->
console.log "processing card"
card =
number: $(page.cardNumber).val()
cvc: $(page.cardCode).val()
expMonth: $(page.cardMonth).val()
expYear: $(page.cardYear).val()
Stripe.card.createToken(card, subscription.handleStripeResponse);
handleStripeResponse: (status, response) ->
if response.error
console.log "error"
$(page.stripeError).text(response.error.message)
$(page.createButton).attr('disabled', false)
alert ("bla")
else
alert("success: " + response.id)
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
subs = new Subscription
subs.setupForm()
的問題是,當我點擊提交按鈕,我得到異常:
Uncaught TypeError: Object #<HTMLInputElement> has no method 'processCard'
我相信這是由以下事實引起的通過點擊事件self
調用的方法是觸發事件的html元素。而通過自我我需要JavaScript對象。
有關如何解決此問題的任何線索?
謝謝,