$(function(){
//用户验证按钮点击事件
$("#types").change(function(){
//获得大类值
var types = $("#types").val();
var url = $("#url").val();
if(url==null || url==''){
alert("Request Failed!");
}
if(types == null || types == '0'){
//删除所有子元素
$("#type option").remove();
//添加元素
$("#type")[0].options.add(new Option('全部','0'));
}else{
/**
* post 请求
* 1. 请求的url
* 2. 传输参数
* 3. 返回方法
*/
url = url + types;
$.post(url,null,function(response){
//分裂返回字符串
var typeInfo = response.split(",");
//删除所有子元素
$("#type option").remove();
//添加元素
$("#type")[0].options.add(new Option('全部','0'));
for(var i = 0 ;i < typeInfo.length ; i+=2){
$("#type")[0].options.add(new Option(typeInfo[i+1],typeInfo[i]));
}
});
}
});
});
jquery ajax 联动菜单
最新推荐文章于 2025-04-28 20:03:49 发布