从数据库中选择父选项字段时填充子选项字段的简单方法)

Easy method to populate sub options field on selecting parent option field from database )

本文关键字:选项 字段 简单 方法 填充 选择 数据库      更新时间:2023-09-26
<select><option>tv</option></select> //parent
<select><option>model</option></select> //sub select
我想在从

父级选择时用电视型号或移动型号填充子字段

像这样:

<select id="mySelectTV"><option>tv</option></select> //parent
<select><option>model</option></select> //sub select

var x = document.getElementById("mySelectTV");
var option = document.createElement("option");
option.text = "music chanel";
x.add(option);

或使用循环

var chanels = ['chanel 1', 'chanel 2', 'chanel 3'];
var x = document.getElementById("mySelectTV");
var option = document.createElement("option");
for(var i=0; i< chanels.length; i++){
   option.text = chanels[i] ;
   x.add(option);
}