javaScript之鼠标操作(onmouseover)

javaScript之鼠标操作(onmouseover)

<input type="checkbox" onmouseover="alert('a')" />

onmouseover:当鼠标移动到checkbox这个元素上时,会发生““里面的指令
alert(‘a’):弹出提示窗,内容为a

<input type="checkbox" onmouseover="document.getElementById('div1').style.display='block';" />

当鼠标移到“checkbox”时,元素div1的style中的display变成block

onmouseout="document.getElementById('div1').style.display='none';"

当鼠标移出checkbox这个元素时,元素div1的style中的display变成none

记住密码提示框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style type="text/css">
    #div1 {
        width: 100px;
        height: 50px;
        background: #999;
        border: 1px solid #000;
        display: none;
    }
</style>
<body>
    <label onmouseover="document.getElementById('div1').style.display='block';" onmouseout="document.getElementById('div1').style.display='none';"><input type="checkbox" />自动登录</label>
    <div id="div1">缤纷维生素软糖</div>
</body>
</html>

换class

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style type="text/css">
    div {
        width: 100px;
        height: 100px;
        background: red;
    }
    .box {
        width: 200px;
        height: 200px;
        background: green;
    }
</style>
<body>
    <div id="div1" onmouseover="document.getElementById('div1').className='box';"onmouseout="document.getElementById('div1').className='';"></div>
</body>
</html>

网页换肤

<input id="btn1" type="button" value="皮肤1" onclick="document.getElementById('link1').href='css1.css';">

当点击“皮肤1”的时候css样式使用css1的样式

JS中函数的使用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
<style type="text/css">
    #div1 {
        width: 100px;
        height: 100px;
        background: red;
    }
</style>
<script type="text/javascript">
    function toGreen(){
        var oDiv1=document.getElementById('div1');
        oDiv1.style.width='200px';
        oDiv1.style.height='200px';
        oDiv1.style.background='green';
    }
    function toRed(){
        var oDiv1=document.getElementById('div1');
        oDiv1.style.width='100px';
        oDiv1.style.height='100px';
        oDiv1.style.background='red';
    }
</script>
</head>
<body>
    <div id="div1" onmouseover="toGreen()" onmouseout="toRed()"></div>
</body>
</html>
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值