![](/img/trans.png)
[英]javascript how to change the color of links onmouseover table cell?
[英]How to change the color of a cell of a table in javascript
这是我的功能
<script>
function colorChange() {
document.getElementById('change').bgcolor="#00CC99";
}
</script>
这是我的桌子
<?php>
echo("<table border=\"1\" cellpadding=\"5\"><tr>\n");
if($dayArray["month"] == $mydate[month])
{
echo ("<td id=\"change\" bgcolor=\"#FF99FF\">
<a href=\"javascript:colorChange()\"</a>")></td>\n");
}
echo (</table>);
但细胞的颜色不会改变。 有谁能够帮助我?
没有像bgcolor
这样的属性,但是有一个属性,但你应该使用element.style:
document.getElementById('change').style.background = "#00CC99";
要么
document.getElementById('change').style.backgroundColor = "#00CC99";
或者,如果您只需要更改属性
document.getElementById('change').setAttribute('bgcolor', '#00CC99');
使用嵌入在php echo
语句中的html
你的代码看起来非常混乱。 改变这个:
<table border="1" cellpadding="5"><tr>
<?php
if($dayArray["month"] == $mydate[month])
{
?>
<td id="change" style="background:#FF99FF"><a href="javascript:colorChange()">></a></td>
<?php
}
?>
</tr>
</table>
使用Javascript:
//There is no property called 'bgcolor', use style.backgroundColor instead.
function colorChange(){
document.getElementById('change').style.backgroundColor="#00CC99"; bgcolor
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.