更改标签的文本

时间:2016-03-02 19:30:26

标签: javascript html

当指针变为指针并将鼠标悬停在框上然后将文本更改为“箭头”时,将标签文本更改为“手动”...这是我的代码

<html>
<style>
  #box:hover {
    background-color: red;
  }
  #box {
    width: 300px;
    height: 300px;
    border: 1px solid;
    background-color: black;
  }
</style>

<body>
  <div id="box" onmouseover="myFunction()"></div>
  <label id="lab">arrow</label>
</body>

<script>
  function myFunction() {
    document.getElementById("lab").innerHTML = "hand";
    document.getElementById("box").style.cursor = "pointer"
  }
</script>

</html>

1 个答案:

答案 0 :(得分:2)

您可以将onmouseout添加到mouseout的触发功能。

&#13;
&#13;
#box:hover {
  background-color: red;
}
#box {
  width: 300px;
  height: 300px;
  border: 1px solid;
  background-color: black;
}
&#13;
<div id="box" onmouseover="myFunction(true)" onmouseout="myFunction(false)"></div>
<label id="lab">arrow</label>
<script>
  function myFunction(over) {
    if (over) {
      document.getElementById("lab").innerHTML = "hand";
      document.getElementById("box").style.cursor = "pointer"
    } else {
      document.getElementById("lab").innerHTML = "arrow";
    }
  }
</script>
&#13;
&#13;
&#13;