Super simple JS linkage code, but you need to use it in conjunction with jquery, you can also modify it yourself to code that does not require any JS library.
Copy code code as follows:
<tr>
<th>First-level classification</th><td>
<select name = "subsidary_cat_id" onchange = "linkage ('. subsidary_cat_id', '. Cat_id');">
<option> Please select </option>
</select>
<script language = "javascript">
Var linkage_data = {$ list_file_category}; // Initialize level data, {$ list_file_category} is the data of the json_encode of php.
function linkage(parent_dom,son_dom){
var Parent_id = 0;
if (Parent_Do) {
paint_id = $ (Parent_Do). Val ();
}
$(son_dom).empty();//Clear the drop-down first
var html='<option>Please select </option>';
$.each(linkage_data,function(key,value){
if (value.parent_id == paint_id) {
html+= "<option value = '"+value.id+"'>" "+value.name+" </option> "";
}
});
$ (SON_DOM) .append (HTML);
}
Linkage ('', ". Subsidiary_cat_id") // Not upper -level nodes, indicated as the first level of data
</script>
</td> </tr>
<tr> <th> secondary directory </th> <td>
<select name = "cat_id">
<option> Please select </option>
</select> </td> </tr>