开发者

Multiple jQuery extensions in the same CoffeeScript file

开发者 https://www.devze.com 2023-04-12 22:21 出处:网络
I want to put more than one jquery extension in the same file.I have the following in one file: do($ = jQuery) ->

I want to put more than one jquery extension in the same file. I have the following in one file:

do($ = jQuery) ->
  $.fn.addAlternatingStyles = ->
    $(@).children('tr').not('.exclude').hover(
      -> $(@).addClass('hoverrow')
      -> $(@).removeClass('hoverrow')
    )

do($ = jQuery) ->  
 开发者_StackOverflow中文版 $.fn.stripe = ->
    $(@).children('tr:even').addClass('evenrow')
    $(@).children('tr:odd').addClass('oddrow')

It does not recognise the second extension, i.e. stripe.

Can anyone point me in the right direction?


You don't need to use separate do.

do($ = jQuery) ->
  $.fn.addAlternatingStyles = ->
    $(@).children('tr').not('.exclude').hover(
      -> $(@).addClass('hoverrow')
      -> $(@).removeClass('hoverrow')
    )

  $.fn.stripe = ->
    $(@).children('tr:even').addClass('evenrow')
    $(@).children('tr:odd').addClass('oddrow')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号