我有<table>
一个mysql
使用php
. 每个<tr style="background-color:;">
记录都存储在数据库中。我做了一个小Javascript
,当用户选择(onfocus
)或取消选择(onblur
)时<input>
,<tr>
会改变颜色。我已经设置好了,所以在选择时颜色会是红色,但我希望它在取消选择后恢复为默认颜色。
这是我的代码片段,位于while()
循环中,其中$i
递增:
<tr id="row$i">
<td><input type="text" onfocus="attON('row$i')" onblur="attOFF('row$i')"></td>
</tr>
这是我的功能:
function attON(id)
{
var row = document.getElementById(id);
row.style.backgroundColor = "#FF0000";
}
function attOFF(id)
{
var row = document.getElementById(id);
row.style.backgroundColor = "";
}
我相信你会猜到,backgroundColor
不会变回它的默认值,而是会改变<table>
颜色。我在想也许捕获默认颜色function attON(id)
并将其设置为全局变量将是答案,但我不知道该怎么做。显然,欢迎任何其他想法。干杯!