First, from the server side, bind the drop-down list, and add the text name of the level-2 drop-down to the ID of the level-1 drop-down according to certain rules.
Copy codeThe Code is as follows:
Var options = new Array ();
$ (Document). ready (function (){
// Second-level linkage
$ ('# DdlPages'). children ('option'). each (function (I ){
Options [I] = '<option value = "' + $ (this ). val () + '">' + $ (this ). text () + '</option> ';
}); // Put the option List in the array
$ ('# DdlPages option: gt (0)'). remove (); // clear the drop-down list
$ ('# DdlSubsystems'). bind ('change', function () {// register an event
Var systemname = $ ('# ddlSubsystems option: selected'). text ();
For (var j = 0; j <options. length; j ++ ){
$ ('# DdlPages'). append (options [j]);
} // The option List is initialized first.
$ ('# DdlPages option: gt (0)'). each (function (I) {// traverse exclusion
Var textname = $ (this). text ();
Var index = textname. indexOf ('-' + systemname );
If (index <0 ){
$ (This). remove ();
} Else {
$ (This). text (textname. substring (0, index ));
}
});
$ ('# DdlPages'). val (0); // The first row is selected by default.
});
});