zoukankan      html  css  js  c++  java
  • jquery里的on方法使用

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <script src="js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
    <title></title>
    <style type="text/css">
    *{
    margin: 0;
    padding: 0;
    }
    .divbox{
    300px;
    height: 200px;
    overflow: hidden;
    }
    </style>
    </head>
    <body>
    <div class="divbox">
    <img src="img/f1.jpg"/>
    </div>
    <p>测试文本</p>
    <script type="text/javascript">
    $(function(){
    $(".divbox").on("click",show);
    function show(){
    console.log("fsfsf") //绑定一个事件
    }
    $(".divbox").off("click"); //移除on所绑定的方法



    $(".divbox").on("click mouseover",show);
    function show(){
    console.log("fsfsf") //不同事件绑定同个方法
    }


    $(".divbox").on({
    mouseover:show,
    mouseout:hide
    })
    function show(){
    $("p").css({"backgroundColor":"#ff0000"})
    } //不同事件绑定不同方法
    function hide(){
    $("p").css({"backgroundColor":"#fff"})
    }


    //注意:使用on方法必须使用jquery1.7版本以上才有效。。
    })

    </script>
    </body>
    </html>

  • 相关阅读:
    Leetcode: Reverse Integer
    Leetcode: Two Sum
    Leetcode: Path Sum
    make distclean
    makefile 中 foreach
    nor flash 和 nand flash
    端口(port)的安全模式(security mode)
    单片机入门(二)
    单片机入门(一)
    kworker
  • 原文地址:https://www.cnblogs.com/luoguixin/p/6111887.html
Copyright © 2011-2022 走看看