Created
January 15, 2010 05:17
-
-
Save yuroyoro/277829 to your computer and use it in GitHub Desktop.
This file contains 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
jQuery(function ($) { | |
$.fn.ajaxDynamicSelect = function (target ,options) { | |
var opt = $.extend({ | |
url:'', // JSONを返すURLを設定 | |
paramName:'selectedValue', // JSONを取得する際にサーバに送るパラメータ名 | |
labelProperty:'text', // JSONの中でSelectのlabelに該当するプロパティ名 | |
valueProperty:'value' // JSONの中でSelectのvalueに該当するプロパティ名 | |
},options); | |
$(this).change( function(e){ | |
var param = {}; | |
param[opt.paramName] = $(this).val(); | |
$.getJSON( opt.url,param , | |
function(json){ | |
$(target).empty(); | |
for(var i = 0 ;i < json.length; i++){ | |
$(target).append( | |
$(document.createElement('option')) | |
.attr({value:json[i][opt.valueProperty] }) | |
.text(json[i][opt.labelProperty]) | |
); | |
} | |
} | |
); | |
}); | |
};}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment