级联下拉列表的实现

[b]原创!转载请注明地址[/b] [color=blue][url]http://ycde2009.iteye.com/blog/1990738[/url][/color]
在前端的组件上绑定事件,在该事件中使用ajax来异步请求,将返回结果组装成前台html代码。
//修改页面时下拉框的连动
//品牌修改时 连动车型


$("#brandID").change(changeBrand_Update);
function changeBrand_Update(){
var value =$("#brandID").val();
$("#vehicleModelID").html("");
if(!value || "0"==value)
{
return;
}
$.ajax({
url: "${pageContext.request.contextPath}/brandJson?brandID="+value,
dataType: "json",
success:function(formData){
var html = "";
$.each(formData.entity,function(i,n){
if(n.entityID == $("#vehicleModelID_hidden").val())
{
html = html + "<option selected value="+n.entityID+">"+n.name+"</option>"
}
else
{
html = html + "<option value="+n.entityID+">"+n.name+"</option>"
}
});
$("#vehicleModelID").html(html);
}
});
};

else
{
html = html + "<option value="+n.entityID+">"+n.name+"</option>"
}
});
$("#vehicleModelID").html(html);
}
});
};
发布了25 篇原创文章 · 获赞 0 · 访问量 5101

猜你喜欢

转载自blog.csdn.net/ycde2009/article/details/84512834
今日推荐