Created
September 2, 2011 14:08
-
-
Save liwh/1188679 to your computer and use it in GitHub Desktop.
district
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RegionUtils = | |
init: (seed = [], region = '.region') -> | |
$(region).each -> | |
selects = $('select', this) | |
selects.unbind('change') # 避免多次绑定change事件 | |
selects.change -> | |
$this = this | |
select_index = selects.index($this) + 1 | |
select = selects.eq(select_index) | |
if $(this).val() and select[0] | |
$.get "/district/" + $(this).val(), (data) -> | |
result = eval(data) | |
options = select[0].options | |
$("option:gt(0)", select).remove() | |
$.each result, (i, item) -> options.add new Option(item[0], item[1]) | |
value = seed[select_index] | |
select.val(value).change() if value # 级联回显 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这个方法有两个作用: