zoukankan      html  css  js  c++  java
  • dom事件

    HTML 事件的例子:

    • 当用户点击鼠标时
    • 当网页已加载时
    • 当图像已加载时
    • 当鼠标移动到元素上时
    • 当输入字段被改变时
    • 当提交 HTML 表单时
    • 当用户触发按键时
    <html>
    <head>
    </head>
    <body>
    
    <p>点击按钮就可以执行 <em>displayDate()</em> 函数。</p>
    
    <button id="myBtn">点击这里</button>
    
    <script>
    document.getElementById("myBtn").onclick=function(){displayDate()};
    function displayDate()
    {
    document.getElementById("demo").innerHTML=Date();
    }
    </script>
    
    <p id="demo"></p>
    
    </body>
    </html> 
    <html>
    <body onload="checkCookies()">
    
    <script>
    function checkCookies()
    {
    if (navigator.cookieEnabled==true)
        {
        alert("已启用 cookie")
        }
    else
        {
        alert("未启用 cookie")
        }
    }
    </script>
    
    <p>提示框会告诉你,浏览器是否已启用 cookie。</p>
    </body>
    </html>
    <html>
    <head>
    <script>
    function myFunction()
    {
    var x=document.getElementById("fname");
    x.value=x.value.toUpperCase();
    }
    </script>
    </head>
    <body>
    
    请输入英文字符:<input type="text" id="fname" onchange="myFunction()">
    <p>当您离开输入字段时,会触发将输入文本转换为大写的函数。</p>
    
    </body>
    </html>
    <html>
    <body>
    
    <div onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color:green;120px;height:20px;padding:40px;color:#ffffff;">把鼠标移到上面</div>
    
    <script>
    function mOver(obj)
    {
    obj.innerHTML="谢谢"
    }
    
    function mOut(obj)
    {
    obj.innerHTML="把鼠标移到上面"
    }
    </script>
    
    </body>
    </html>
    <html>
    <body>
    
    <div onmousedown="mDown(this)" onmouseup="mUp(this)" style="background-color:green;color:#ffffff;90px;height:20px;padding:40px;font-size:12px;">请点击这里</div>
    
    <script>
    function mDown(obj)
    {
    obj.style.backgroundColor="#1ec5e5";
    obj.innerHTML="请释放鼠标按钮"
    }
    
    function mUp(obj)
    {
    obj.style.backgroundColor="green";
    obj.innerHTML="请按下鼠标按钮"
    }
    </script>
    
    </body>
    </html>

    <html>
    <head>
    <script>
    function myFunction(x)
    {
    x.style.background="yellow";
    }
    </script>
    </head>
    <body>

    请输入英文字符:<input type="text" onfocus="myFunction(this)">

    <p>当输入字段获得焦点时,会触发改变背景颜色的函数。</p>

    </body>
    </html>

    <html>
    <body>
    
    <div onmousedown="mDown(this)" onmouseup="mUp(this)" style="background-color:green;color:#ffffff;90px;height:20px;padding:40px;font-size:12px;">请点击这里</div>
    
    <script>
    function mDown(obj)
    {
    obj.style.backgroundColor="#1ec5e5";
    obj.innerHTML="请释放鼠标按钮"
    }
    
    function mUp(obj)
    {
    obj.style.backgroundColor="green";
    obj.innerHTML="请按下鼠标按钮"
    }
    </script>
    
    </body>
    </html>
  • 相关阅读:
    vue换一换功能原型
    一些文章收集
    mint-ui popup自动关闭
    vue 实现二选一列表
    用数组实现矩阵乘法
    表格
    表单
    django项目创建和结构解释
    js操作元素样式
    操作标签属性
  • 原文地址:https://www.cnblogs.com/liuyudong0825/p/4814278.html
Copyright © 2011-2022 走看看