用javascript更改表格的颜色 [英] change colors of table with javascript
本文介绍了用javascript更改表格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图为我的考试学习,我认为我正在做这个权利...
我想要改变表格的颜色(字体或背景),取决于您点击哪个单元格
我认为我是指右表,但这段代码不工作......我不知道我做错了什么,我会很感激你可以提供任何帮助或解释。
I'm trying to study for my exam and I thought I was doing this right... I want to change the color of the table (font or background) depending on which cell you click I thought I was referring to the table right, but this code isn't working... I have no idea what I'm doing wrong, I'd appreciate any help or explanation you can offer
<html>
<script language="text/JavaScript">
function changeFont(color){
document.getElementbyId("miTabla").style.backgroundColor = color;
}
function changeBack(color){
document.getLementbyId("miTabla").style.font.color = color;
}
</script>
<body>
<header>Tabla de ejemplo</header>
<table id="miTabla" border="2">
<tr>
<td>changeFont</td>
<td onclick="changeFont('#FF0000');">red</td>
<td onclick="changeFont('#FFFF00');">yellow</td>
<td onclick="changeFont('#0000FF');">blue</td>
</tr><tr>
<td>changeBack</td>
<td onclick="changeBack('#FFFFFF');">white</td>
<td onclick="changeBack('#808080');">gray</td>
<td onclick="changeBack('#000000');">black</td>
</tr>
</table>
</body>
</html>
推荐答案
更改 getLementbyId
和 getElementbyId
至 getElementById
并更改 font.color
到 color 。
function changeFont(color){
document.getElementById("miTabla").style.color = color;
}
function changeBack(color){
document.getElementById("miTabla").style.backgroundColor = color;
}
changeFont
也可能更适当地命名为 changeForeground
。
changeFont
might also be more appropriately named changeForeground
.
这篇关于用javascript更改表格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文