douwei9759 2013-08-09 10:28
浏览 91

使用<table>标记中的JavaScript更改CSS属性

I am developing an online quiz application and it provides a list of all the questions and when a user clicks a question number, the respective question should be shown. When a user clicks on any question number, the question numbered cell's background color should be changed. For this my JS is as follows

<script>
function changecolor(x)
{
    document.getElementById(x).style.background-color="#4ead3a";
}
 </script>

and the table code is as follows:

<table border=1>
<tr>            
<?php
for($i=1;$i<=$count;$i++)
{ ?>
<td id="<?php echo  $i; ?> " align="center" style="width:50px"    onclick="changecolor(id)" >
    <a href="http://127.0.0.1/example/runquiz.php?x=<?php echo  $i; ?>" ><?php   echo  $i; ?> </a> 
    <input type="hidden" name=<?php echo  $i; ?> value="" >
</td>
<?php }
 ?>
 </tr></table>

and the css is as follows

td{
vertical-align:middle;
background-color:#dbd6d2;
border:1px solid #000000;
border-width:0px 1px 1px 0px;
text-align:center;
padding:7px;
font-size:10px;
font-family:Arial;
font-weight:bold;
color:#000000;

}

But when I click on any cell, the background color is remaining the same. I am new to use CSS with JS. Please help me. Thanks in advance

  • 写回答

3条回答 默认 最新

  • douhuang5623 2013-08-09 10:31
    关注

    Use

    document.getElementById(x).style.backgroundColor="#4ead3a";
    

    http://www.w3schools.com/jsref/prop_style_backgroundcolor.asp

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题