Jquery` .on()`获取第二个参数作为DOM

时间:2015-01-25 10:25:28

标签: javascript jquery coffeescript

代码(在CoffeeScript中):

$shoppingCartItems.on 'click', $('a.data-trash'), ->
  if confirm 'Remove this item?'
    console.log $this
    $.post '/delete-cart-item',
      id: $this.attr 'data-cart-id'
    .done (e) ->
      alert e.message
      if e.type is 'success'
        $this.remove()
        $itemNumber.text e.data.countItems + ' item(s) - ' + e.data.total
        $subTotal.text e.data.sub_total
        $vat.text e.data.vat
        $total.text e.data.total
      return
    .fail (xhr, status, e) ->
      alert xhr.responseText
      return
  false

预期结果:

  

$this will be clicked element of $('a.data-trash')

现实:

  

$this equal to $shoppingCartItems.

问:

如何让$this等于预期结果?

0 个答案:

没有答案