如果更改下拉列表中的选定项目,我正在尝试更改表格单元格的背景颜色。我对文本框使用相同的 javascript,它工作正常。在萤火虫中,当从选择中调用时,“单元格”是未定义的。
这是我的脚本/html
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function changeText(cell, shown, hidden)
{
if (shown == hidden)
{
cell.style.backgroundColor="red";
}
else
{
cell.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="5">
<tr>
<td>
Cell 1
</td>
<td>
<select id="catBlah" OnChange="changeText(this.parentnode, this.options[this.selectedIndex].value, '789');">
<option value=""></option>
<option selected="selected" value="789">Item 1</option>
<option value="000">Item 2</option>
<option value="456">Item 3</option>
<option value="123">Item 4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="text" value="blue" onchange="changeText(this.parentNode, this.value, 'blue');" />
</td>
<td>
Cell 4
</td>
</tr>
</table>
</form>
</body>
</html>
如果我只是传递选择对象(使用“this”而不是“this.parentnode”),我可以更改选择的背景颜色(可能符合要求),但我不知道如何获取父节点。
谢谢