Dar*_*rov 14
您可以将员工信息存储到javascript对象中:
var employees = [
{ id: '1', sex: 'm', city: 'Paris' },
{ id: '2', sex: 'f', city: 'London' },
... etc fill this in a foreach loop
];
Run Code Online (Sandbox Code Playgroud)
接下来,绑定到选择框的change事件:
$(function()
{
$('select#id_of_the_employees_select').change(function(e) {
// Get the current selected employee id
var selectedEmployeeId = $(this).val();
// find the corresponding employee in the list
var emps = $.grep(employees, function(n, i) {
return n.id == selectedEmployeeId;
});
if (emps.length > 0) {
var employee = emps[0];
// fill the form elements with employee data:
$('#employee_sex').val(employee.sex);
$('#employee_city').val(employee.city);
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33155 次 |
| 最近记录: |