English 中文(简体)
用javascript改动表格的颜色
原标题:change colors of table with 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.colorcolor/code>。

        function changeFont(color){
            document.getElementById("miTabla").style.color = color;
        }
        function changeBack(color){
             document.getElementById("miTabla").style.backgroundColor = color;
        }

<代码>changeFont也可更恰当地命名为changeForeground

问题回答

设置<代码>后继场Color是正确的,但与font.color有关的内容是什么? 什么时候?

Just use Format.color.

另外,在第二版中确定“植被<>><>>>>>ementById”。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签