首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >保持高亮显示记录甚至页面刷新的javascript

问保持高亮显示记录甚至页面刷新的javascript
EN

Stack Overflow用户
提问于 2017-07-22 11:55:06
回答 1查看 25关注 0票数 0

我使用以下代码突出显示一个表中的多个记录行。当我单击按钮行selected.But时,我刷新的页面高亮显示消失了。有人可以帮助我如何保持突出显示的记录,即使页面被刷新。

代码语言:javascript
复制
<script>
function highlight(ctrl) {
  var parent = ctrl.parentNode.parentNode;

  if(parent.classList == "New backChange") {
    parent.classList.remove("backChange");
  }
  else {
    parent.classList.add("backChange");
  }
}
</script>

<style>
.backChange{
    background:red;
}
</style>
<table id="appTable" style="margin-top:10px;" margin-left:10px;="" border="1">
  <tbody>
    <tr>
      <th>Select</th>
      <th>Name</th>
      <th>Location</th>
      <th>Action</th>
    </tr>
    <tr class="New">
      <td><input id="mapCheck" name="myTextEditBox" type="checkbox"></td>
      <td width="140">Name</td>
      <td width="200">Location</td>
      <td><button type="button" onclick="highlight(this)">select</button></td>
    </tr>
    <tr class="New">
      <td><input id="mapCheck" name="myTextEditBox" type="checkbox"></td>
      <td width="140">Name</td>
      <td width="200">Location</td>
      <td><button type="button" onclick="highlight(this)">select</button></td>
    </tr>
    <tr class="New">
      <td><input id="mapCheck" name="myTextEditBox" type="checkbox"></td>
      <td width="140">Name</td>
      <td width="200">Location</td>
      <td><button type="button" onclick="highlight(this)">select</button></td>
    </tr>
    <tr class="New">
      <td><input id="mapCheck" name="myTextEditBox" type="checkbox"></td>
      <td width="140">Name</td>
      <td width="200">Location</td>
      <td><button type="button" onclick="highlight(this)">select</button></td>
    </tr>
  </tbody>
</table>

​

​

EN

回答 1

Stack Overflow用户

发布于 2017-07-22 12:13:18

因为当页面刷新时,className会被重置。您可以在刷新页面时使用localStorage保存和读取值

this is usage of localStoeage

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45250486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档