jquery.china_city.js.coffee 598 B

1234567891011121314151617
  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 !$(@).val() # empty all children city
  8. $("option:gt(0)", next_select).remove()
  9. next_select.change()
  10. else if next_select[0] # init next child
  11. $.get "/china_city/#{$(@).val()}", (data) ->
  12. $("option:gt(0)", next_select).remove()
  13. next_select[0].options.add(new Option(option[0], option[1])) for option in data
  14. $ ->
  15. $('.city-group').china_city()
  16. )(jQuery)