Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有特定单元格功能的下拉菜单_Javascript_Html - Fatal编程技术网

Javascript 具有特定单元格功能的下拉菜单

Javascript 具有特定单元格功能的下拉菜单,javascript,html,Javascript,Html,我有一个包含5列的表: <script> function function1() { document.all.myTD.bgColor = "green"; } function function2() { document.all.myTD.bgColor = "grey"; } </script> <tr> <th>aircrift

我有一个包含5列的表:

  <script>
  function function1() {
      document.all.myTD.bgColor = "green";
  }
  function function2() {
      document.all.myTD.bgColor = "grey";
  }
   </script>


            <tr>
                <th>aircrift type</th>
                <th >registration</th>
                <th >arrival time</th>
                <th>departure time</th>
                <th>actions</th>
            </tr>
                <tr>
                <td>aircrift type</td>
                <td >registration</td>
                <td id="myTD">arrival time</td>
                <td>departure time</td>
                <td><select> <option onclick="function1()">airborne</option><option onclick="function2()">airborne</option></select></th>
            </tr>

函数function1(){
document.all.myTD.bgColor=“绿色”;
}
函数function2(){
document.all.myTD.bgColor=“灰色”;
}
空运式
登记
到达时间
出发时间
行动
空运式
登记
到达时间
出发时间
机载
在本例中,我需要在下拉菜单中插入一些操作。如果飞机在空中飞行,我需要到达时间单元格变为绿色,如果着陆时间为灰色。
我想为每一行创建此函数,然后将其保存到phpmyadmin DB。

如注释中所述-
选项
元素本身不会触发或接收事件-它们被传递到父元素,因此您将在
选择
标记上分配事件侦听器

如果您向事件处理程序传递一个
事件和一个值,您可以很容易地在特定单元格上设置所需的颜色,方法是将树向上引用到父单元格,向下引用到特定单元格(即:parentNode.parentNode,如下所示)


空运式
登记
到达时间
出发时间
行动
波音747
BA747-01KDS
18:30
16:30
请选择
空运的
降落
寄宿
加油
转换
空中客车A380
KLM380-FD76
19:45
15:00
请选择
空运的
降落
寄宿
加油
转换
A10疣猪
WB-USAF-0034
20:00
19:20
请选择
空运的
降落
寄宿
加油
转换
功能设置颜色(e、v){
e、 预防默认值();
var tr=e.target.parentNode.parentNode;
开关(v){
“空降”案例:
tr.childNodes[3].style.backgroundColor='green';
打破
“落地”案例:
tr.childNodes[3].style.backgroundColor='gray';
打破
“登机”案件:
tr.childNodes[3].style.backgroundColor='red';
打破
“加油”案例:
tr.childNodes[3].style.backgroundColor='yellow';
打破
“转换”案例:
tr.childNodes[3].style.backgroundColor='purple';
打破
}
}
我提到的修改如果您希望根据所选值设置整行颜色,您可以将上面的相关行更改为:

tr.style.backgroundColor='<COLOUR>';
tr.style.backgroundColor='';

如注释中所述,
选项
元素本身不会触发或接收事件,它们会传递给父元素,因此您将在
选择
标记上分配事件侦听器

如果您向事件处理程序传递一个
事件和一个值,您可以很容易地在特定单元格上设置所需的颜色,方法是将树向上引用到父单元格,向下引用到特定单元格(即:parentNode.parentNode,如下所示)


空运式
登记
到达时间
出发时间
行动
波音747
BA747-01KDS
18:30
16:30
请选择
空运的
降落
寄宿
加油
转换
空中客车A380
KLM380-FD76
19:45
15:00
请选择
空运的
降落
寄宿
加油
转换
A10疣猪
WB-USAF-0034
20:00
19:20
请选择
空运的
降落
寄宿
加油
转换
功能设置颜色(e、v){
e、 预防默认值();
var tr=e.target.parentNode.parentNode;
开关(v){
“空降”案例:
tr.childNodes[3].style.backgroundColor='green';
打破
“落地”案例:
tr.childNodes[3].style.backgroundColor='gray';
打破
“登机”案件:
tr.childNodes[3].style.backgroundColor='red';
打破
“加油”案例:
tr.childNodes[3].style.backgroundColor='yellow';
打破
“转换”案例:
tr.childNodes[3].style.backgroundColor='purple';
打破
}
}
我提到的修改如果您希望根据所选值设置整行颜色,您可以将上面的相关行更改为:

tr.style.backgroundColor='<COLOUR>';
tr.style.backgroundColor='';

选项
元素无法接收事件-是
选择
元素(即:父元素)接收事件。Select元素也应该有一个名称-但如果您没有将其值发送到表单,则可能不是100%必要的重复项或
选项
元素不能接收事件-接收事件的是
Select
元素(即父元素)。Selec