This article mainly introduces the implementation of JQuery asynchronous loading of the infinite drop-down box cascade function. For more information, see
The Code is as follows:
/*
JQuery asynchronously loads the infinite pole drop-down box cascade Function
Zjy
*/
(Function ($ ){
$. AjaxSetup ({async: false });
Var url = "";
Var parameter = "";
$. Fn. extend ({
Load: function (urlPath ){
Url = urlPath. url;
Parameter = urlPath. parameter;
$ ("# Ddl1"). append ("Select");
$. GetJSON (url, parameter, function (data ){
$. Each (data. rows, function (I, row ){
$ ("# Ddl1"). append ($ (""Maid (row. text ));
});
$ ("# Ddl1"). change (function () {$ (this). Select ($ (this). val (), this );});
});
$ (This). Selected (parameter. parentId, $ ("# ddl1 "));
},
Select: function (parentId, obj ){
// Debugger;
If (parentId = "0 "){
Return;
}
Parameter. parentId = parentId;
$. GetJSON (url, parameter, function (data ){
$ (Obj). nextAll (". ddl"). remove ();
If (data! = Null ){
$ ("",{"Class": "ddl ",Change: function (){$ (This). Select ($ (this). val (), this );}}). AppendTo ($ ("# cascade "));$ (". Ddl") [$ (". ddl"). length-1]). append ("Select");$. Each (data. rows, function (I, row ){$ (". Ddl") [$ (". ddl"). length-1]). append ($ (""Maid (row. text ));});}});$ (This). Selected (parentId, $ (obj). nextAll (". ddl "));},Selected: function (parentId, obj ){$ (This). GetValue ();// Debugger;Var selected = "0," + $ ("# loadselect"). val ();$. Each (selected. split (","), function (I, row ){If (row = parentId ){// Debugger;$ (Obj). val (selected. split (",") [I + 1]);$ (Obj). change ();}});},GetValue: function (){Var ddlValue;Var ddlCount = $ (". ddl"). length;For (var I = ddlCount-1; I> = 0; I --){If (I! = 0 ){If ($ (". ddl") [I]). val ()! = 0 ){DdlValue = $ (". ddl") [I]). val ();Break;}} Else {If ($ (". ddl") [I]). val () = 0 ){DdlValue = 0;Break;} Else {DdlValue = $ (". ddl") [I]). val ();Break;}}}$ ("# Selectvalue"). val (ddlValue );},});}) (JQuery );Call Method