jquery.china_city.js.coffee 445 B

1234567891011121314
  1. (($) ->
  2. $.fn.china_city = () ->
  3. @each ->
  4. selects = $(@).find('.city-select')
  5. selects.change ->
  6. next_select = selects.eq(selects.index(@) + 1)
  7. if next_select[0]
  8. $.get "/china_city/#{$(@).val()}", (data) ->
  9. $("option:gt(0)", next_select).remove()
  10. next_select[0].options.add(new Option(option[0], option[1])) for option in data
  11. $ ->
  12. $('.city-group').china_city()
  13. )(jQuery)