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