ITPub博客

首页 > 应用开发 > > HTML中thead和tbody中的tr不是一种吗?

HTML中thead和tbody中的tr不是一种吗?

作者:founderwzh 时间:2019-08-16 09:22:45 0 删除 编辑

最近在学习JavaScriptDOM有段代码运行我很困惑:

这是body部分的代码:

<body>
  <table>
    <caption>Itinerary</caption>
    <thead>
    <tr>
      <th>When</th>
      <th>Where</th>
    </tr>
    </thead>
    <tbody>
    <tr>
      <td>June 9th</td>
      <td>Portland, <abbr title="Oregon">OR</abbr></td>
    </tr>
    <tr>
      <td>June 10th</td>
      <td>Seattle, <abbr title="Washington">WA</abbr></td>
    </tr>
    <tr>
      <td>June 12th</td>
      <td>Sacramento, <abbr title="California">CA</abbr></td>
    </tr>
    </tbody>
有段js:

复制代码
function highlightRows() {
  if(!document.getElementsByTagName) return false;
  var rows = document.getElementsByTagName("tr");
  for (var i=0; i<rows.length; i++) {
    rows[i].onmouseover = function() {
      this.style.fontWeight = "bold";
    }
    rows[i].onmouseout = function() {
      this.style.fontWeight = "normal";
    }
  }
}
addLoadEvent(highlightRows);

css代码我就不贴了,最后在浏览器的显示状态是这样:

 

鼠标放在下面3个row上面才会有字体变粗的效果,但是第一个thead部分的row就不行,希望大家能告知一下原因,谢谢啦

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4605/viewspace-3142590/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    159
  • 访问量
    739