首页javascriptbackgroundjQuery Style - 如何切换2背景颜色每秒

jQuery Style - 如何切换2背景颜色每秒

我们想知道如何切换2背景颜色每秒。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.7.1.js'></script>
<style type='text/css'>
td.bgimage {
  padding: 10px;
  background: #333;
}

td.bgimage.toggled {
  background: #f00;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    function colorChange(){
        setTimeout(function(){
            $('td.bgimage').toggleClass('toggled');
            colorChange();
        }, 1000);
    }
    colorChange();
});
</script>
</head>
<body>
  <table>
    <tr>
      <td class="bgimage">&nbsp;</td>
    </tr>
  </table>
</body>
</html>