天天看点

对节点操作的思想

<!DOCTYPE html>
<html>
<body>
<!-- onmouseover 这种为固定值用法,后面跟着 函数名字, 在<script>里调用 this 表示参数,这里写了,function里面也要写 -->
<div onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color:green;width:120px;height:20px;padding:40px;color:#ffffff;">把鼠标移到上面</div>

<script>
    var div = document.querySelector('div')
function mOver(div)
{
div.innerHTML="欢迎鼠标移入"
}

function mOut(div)
{
div.innerHTML="感谢鼠标移出"
}
</script>
</body>
</html>