我是 HTML 和 javascript 新手。我编写了下面的代码,当鼠标悬停在按钮上时执行 JavaScript 的 over() 但代码不起作用。
请建议对代码进行一些更改以使其运行。
<html>
<head>
<script type="text/javascript">
function over()
{
document.getElementById("b1").value="You have hovered mouse over me";
}
</script>
</head>
<body>
<button onmouseover="over()" id="b1">Hover mouse over me</button>
</body>
最佳答案
您需要将文本替换为innerHTML 像这样
<html>
<head>
<script type="text/javascript">
function over()
{
document.getElementById("b1").innerHTML="You have hovered mouse over me";
}
</script>
</head>
<body>
<button onmouseover="over()" id="b1">Hover mouse over me</button>
</body>
关于javascript - 按钮上的 onmouseover 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41206016/