联动下拉框 jquery 插件(二)
2011-06-04 16:44
330 查看
<selectid="Select1"></select>
<selectid="Select2"></select>
<selectid="Select3"></select>
<selectid="Select4"></select>
<scriptsrc="Scripts/jquery-1.6.1.min.js"type="text/javascript"></script>
<scriptsrc="Scripts/jQuery.CascadingSelect.js"type="text/javascript"charset="gb2312"></script>
$(function(){
$("#Select1").FillOptions("Ajax/AreaHandler.ashx",{
textfield:"RegionName",
valuefiled:"RegionId"
});
$("#Select1").CascadingSelect($("#Select2"),"Ajax/AreaHandler.ashx",{
textfield:"ProvinceName",
valuefiled:"ProvinceId",
parameter:"r"
},
function(){
$("#Select2,#Select3,#Select4").empty().append('<option>--请选择--</option>').attr('disabled','disabled');
});
$("#Select2").CascadingSelect($("#Select3"),"Ajax/AreaHandler.ashx",{
textfield:"CityName",
valuefiled:"CityId",
parameter:"p"
},
function(){
$("#Select3,#Select4").empty().append('<option>--请选择--</option>').attr('disabled','disabled');
});
$("#Select3").CascadingSelect($("#Select4"),"Ajax/AreaHandler.ashx",{
textfield:"DistrictName",
valuefiled:"DistrictId",
parameter:"c"
});
json格式同上篇
后台参数:
if(context.Request.Params["p"]!=null)
{
sql=String.Format("SELECTCityId,CityNameFROMT_CityWHEREProvinceId='{0}'",context.Request.Params["p"]);
}
插件(jQuery.CascadingSelect.js):
options=$.extend({textfield:'text',
valuefiled:'value',
selectedindexid:0,
parameter:''
},options||{});
$this=$(this);
if($this.children().length===0){$this.append('<option>--请选择--</option>').attr('disabled','disabled');
}
$this.empty().attr('disabled','disabled')
.append('<option>Loadingoptions</option>');
$.getJSON(url,function(response){if(response.count>0){$this.empty().removeAttr("disabled");
$this.append('<option>-请选择-</option>');
$.each(response.data,function(i,item){$this.append($("<option></option>")
.attr("value",eval("item."+options.valuefiled))
.text(eval("item."+options.textfield)));
});
}else{$this.empty().prop("disabled",true)
.append('<option>Noelementsfound</option>');
}})
}
$.fn.CascadingSelect=function(target,url,options,endfn){if(target[0].tagName!="SELECT")throw"targetmustbeSELECT";
if(url.length===0)throw"requestisrequired";
if(options.parameter===undefined)throw"parameterisrequired";
$(this).bind("change",function(){varnewurl="";
urlstr=url.split("?");
newurl=urlstr[0]+"?"+options.parameter+"="+$(this).val();
target.FillOptions(newurl,options);
if(typeofendfn=="function"){endfn();}})
}
$.fn.AddOption=function(text,value,selected,index){option=newOption(text,value);
this[0].options.add(option,index);
this[0].options[index].selected=selected;
}
})(jQuery);
相关文章推荐
- 联动下拉框 jquery 插件(一)
- 联动下拉框 jquery 插件(二)
- 联动下拉框 jquery 插件(一)
- 联动下拉框 jquery插件(三)
- 联动下拉框 jquery插件(三)
- jQuery的下拉框搜索select2插件用法
- 如何通过jQuery实现select下拉框的联动效果
- jQuery插件实现多级联动菜单效果
- 自制Jquery下拉框插件
- jquery插件 autoComboBox 下拉框
- 用jQuery实现省市区三级联动(可做插件)
- 自己编写的仿京东移动端的省市联动选择JQuery插件
- jquery操作select的联动插件FillOptions&CascadingSelect
- select 无限级联动。省市县三级联动。jquery插件
- 用Jquery简单封装一个可重复调用的省市级联动插件
- 地址联动jquery插件的实现
- IE6下使用jquery.bgiframe.js插件解决下拉框覆盖浮动层、Dialog的问题
- 推荐一个很不错的JQuery 下拉框选择插件
- 第29款插件:第24款插件:jquery.chained.js多级联动插件
- 一款基于jQuery的联动Select下拉框