/***jQuery的连锁选择*版权所有(C)2008 Ziadin Givan www.CodeAssembly.com**这个程序是免费软件:你可以重新分发和/或修改它*它根据由*自由软件基金会,许可证版本3,或*(由您选择)任何更高版本。**分发此程序是为了希望它会有用,*但无任何保证;甚至没有*适销性或特定用途的适用性。请参阅*GNU通用公共许可证了解更多详细信息。**您应该已经收到GNU通用公共许可证的副本*以及这个程序。如果没有,请参阅http://www.gnu.org/licenses网站/** *settings={usePost:true,before:function(){},after:functional(){neneneep,默认值:null,参数:{parameter1:“value1”,参数2:“value2”}}*如果usePost为true,则表单将使用POST将参数传递给目标,否则将使用GET*“before”函数在ajax请求之前调用,“after”函数在ajax请求之后调用。*如果defaultValue不为null,则将选择指定的选项。*您可以在settings.parameters中指定要发送到服务器的其他参数。**/;(函数($){jQuery.fn.chainSelect=函数(目标、url、设置){return this.each(function(){$(this).change(function(){设置=$.extend({之后:null,之前:null,usePost:false,defaultValue:空,参数:{'_id':$(this).attr('id'),'_name':$},设置);设置.参数_值=$(this).val();if(settings.before!=空){settings.before(目标);}ajaxCallback=函数(数据,文本状态){$(target).html(“”)//清除旧选项数据=评估(数据)//获取json数组if(数据!=空){对于(i=0;i<数据长度;i++){$(target).get(0).add(新选项(data[i].name,data[i].value),document.all?i:空);}}其他{$(target).get(0).add(新选项('-select a country-',''),document.all?i:空);}if(settings.defaultValue!=空){$(target).val(settings.defaultValue)//选择默认值}其他{$(“option:first”,target).attr(“selected”,“selected”)//选择第一个选项}if(settings.after!=空){settings.after(目标);}$(target).change()//调用下一个链};if(settings.usePost==true){$.post(url,settings.parameters,ajaxCallback);}其他{$.get(url,settings.parameters,ajaxCallback);}});});};})(jQuery);