#### js鼠标的事件--网页事件

本文详细介绍了JavaScript中处理鼠标和输入事件的方法,包括单击、鼠标经过、文本内容改变等常见事件的实现与响应。通过具体实例展示了如何使用这些事件来增强网页交互体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#### js鼠标的事件
onClick-----单击事件
onMouseOver------鼠标经过事件
onMouseOut-------鼠标移出事件
onChang--------文本内容改变事件
onSelect-------文本框选中事件
onFocus-------光标聚集事件
onBlur------移开光标事件
onLoad------网页加载事件
onUnload-----关闭网页事件
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div_test{
            width: 100px;
            height: 100px;
            background-color: aqua;
        }
    </style>
</head>
<body onload="mgs()">
    <!-- 鼠标移出,经过事件 -->
    <div class="div_test" onmouseout="onOut(this)" onmouseover="onOver(this)"></div>
    <script>
        function onOver(ooj){
            ooj.innerHTML = "hello";
        }
        function onOut(ooj){
            ooj.innerHTML = "world";
        }
    </script>
    <form action="">
        <input type="text" onchange="onchangeDemo(this)">
        <input type="text" onselect="changdemo2(this)">
        <input type="text" onfocus="changdemo3(this)">
    </form>
    <script>
        function onchangeDemo(bg){
            alert("内容改变了")
        }
        function changdemo2(bg2){
            bg2.style.background="red";
        }
        function changdemo3(bg3){
            bg3.style.background="red";
        }
        function mgs(){
            alert("网页加载完毕")
        }
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值