jQueryについて質問があります。特定のイベントでjQueryを含むjavascript関数にIDを渡すことはできませんか?
たとえば、load_dl
l は完全に機能します。update_dll
まともに仕事ができなくて困っています。
//Create values for drop down list
var empType = ['Sales Associate', 'New Hire Sales Associate', 'Post-Hire Graduation', 'Senior Supervisor'];
//initialize values
load_ddl(empType, 'empTypeddl');
update_dll('empTypedll', 'empType');
//Populate drop down list function
function load_ddl(arr, id) {
for (i = 0; i < arr.length; i++) {
$('<option/>').val(arr[i]).html(arr[i]).appendTo('#' + id);
}
}
//Update Function
function update_ddl(source_id, target_id) {
$('#' + source_id).change(function() {
alert($('#' + source_id + ' option:selected').attr('value'));
});
}
最も基本的な形式に単純化すると、機能します。IDを渡すことは可能ですか?
$('#empTypeddl').change(function() {
alert($('#empTypeddl option:selected').attr('value'));
});