javascript:JS实现双色表格
来源:优易学  2010-1-15 12:32:33   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  th,td {

  border:solid 1px black;

  width:100px;

  }

  -->

  </style>

  <script type="text/javascript" >

  function color() {

  //把表头设为紫色

  var th = document.getElementById("th");

  th.style.background = "violet"

  //1.得到所有<tr>元素

  var trs = document.getElementsByTagName("tr");

  var i;

  for(i = 1; i <trs.length; i++) {

  //2.改变<tr>元素的背景颜色

  if(i % 2 == 0) {

  trs[i].style.background = "yellow";

  } else {

  trs[i].style.background = "olive";

  }

  }

  }

  window.onload = color;

  </script>

  </head>

  <body>

  <center>

  <table>

上一页  [1] [2] [3] 下一页

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训