Select tag drop down list of secondary linkage cascaded instance code

  • 2020-03-30 01:38:51
  • OfStack

First, from the server side, bind the drop-down list, the text name of the second-level drop-down is named according to certain rules plus the ID of the first-level drop-down.

var options=new Array();
    $(document).ready(function(){
        //The secondary linkage
        $('#ddlPages').children('option').each(function(i){
            options[i]='<option value="'+$(this).val()+'">'+$(this).text()+'</option>';
        });//Put the option list into the array
        $('#ddlPages option:gt(0)').remove();    //Clear the drop-down
        $('#ddlSubsystems').bind('change',function(){        //Register 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 ruled out
                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
        });
    });

Related articles: