工具提示鼠标悬停事件不起作用

时间:2017-09-08 12:01:02

标签: javascript jquery html

当某人将鼠标悬停在按钮上时,我想要更改一些文字。我使用了一个事件处理程序,但它似乎不起作用。有什么想法吗?

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

MyButton.addEventListener('mouseover', function() {
tooltip(1);
});

  function tooltip(thing) {
if (thing = 1) {
document.getElemenyById("tooltipText").innerHTML = "Test!!!";
 }
}
<button type="button" class="btn-primary" id="MyButton">
  Hover Over Me!
</button>

1 个答案:

答案 0 :(得分:0)

document.getElemenyById中有拼写错误,应为document.getElementById

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

MyButton.addEventListener('mouseover', function() {
  tooltip(1);
});

function tooltip(thing) {
  if (thing === 1) { // also use === for comparison not =
    document.getElementById("tooltipText").innerHTML = "Test!!!";
  }
}
<button type="button" class="btn-primary" id="MyButton">
  Hover Over Me!
</button>
<span id="tooltipText">
</span>