您好我想使用Ajax管理下拉菜单中的数据.
数据库字段:
1.id
2.name
教研室
myDesgin.php
<select id="id"></select>
<select id="name"></select>
<select id="department"></select>
Run Code Online (Sandbox Code Playgroud)
1.如果我选择了一个下拉菜单,想要使用Ajax更改另一个下拉菜单取决于所选值.
2.有可用的代码,如果我选择一个下拉列表,它会转到另一个子窗口并使用Ajax以表格格式(如报告)显示数据.
提前致谢.
请给我示例代码,因为我是ajax的初学者,如果有人提供代码解释(对于ajax),最欢迎.
小智 19
是的,检查以下jquery ajax代码.在此示例中,如果您更改"部门",则它将填充"名称"下拉列表.
$(document).on("change", '#department', function(e) {
var department = $(this).val();
$.ajax({
type: "POST",
data: {department: department},
url: 'admin/users/get_name_list.php',
dataType: 'json',
success: function(json) {
var $el = $("#name");
$el.empty(); // remove old options
$el.append($("<option></option>")
.attr("value", '').text('Please Select'));
$.each(json, function(value, key) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
}
});
});Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51722 次 |
| 最近记录: |