Super simple JS two level multi level linkage simple example

  • 2020-03-30 01:44:40
  • OfStack

Super simple JS linkage code, but to cooperate with jquery to use, you can also modify their own not optional JS library code

  <th> The primary classification </th><td>
    <select name="subsidiary_cat_id" class="subsidiary_cat_id" onchange="linkage('.subsidiary_cat_id','.cat_id');">
      <option> Please select a </option>
    <script language="javascript">
    var linkage_data={$list_file_category};//Initialize the cascading data, {$list_file_category} is the data of PHP's JSON_ENCODE, the array has 3 data, id,parent_id,name
    function linkage(parent_dom,son_dom){
        var parent_id=0;
        $(son_dom).empty();//So let's clear the drop down
        var html='<option> Please select a </option>';
                html+="<option value='""'>""</option>";
    linkage('',".subsidiary_cat_id")//Do not pass the parent node, represented as the first level of data
<tr><th> The secondary directory </th><td>
  <select name="cat_id" class="cat_id">
    <option> Please select a </option>

Related articles: