zoukankan      html  css  js  c++  java
  • jQuery之事件绑定

    bind() 方法为被选元素添加一个或多个事件处理程序,并规定事件发生时运行的函数。

    下面是具体的用法:

    <script type="text/javascript">
    $(function(){
        $head = $("#panel h5.head");//选中
        $head.bind("click",function(){//如果点击,就会触发事件,将下面的内容显示出来
            $(this).next().show();
        })
    })
    </script>

    is(":hidden")可以判断对象是否隐藏。

    is(":visible")可以判断对象是否可见。

    <script type="text/javascript">
    $(function(){
        $("#panel h5.head").bind("click",function(){
            var $content = $(this).next();
            if($content.is(":visible")){//如果可见,将其隐藏。如果隐藏,将其可见。
                $content.hide();
            }else{
                $content.show();
            }
        })
    })
    </script>

    mouseover鼠标飘过。

    <script type="text/javascript">
    $(function(){
        $("#panel h5.head").bind("mouseover",function(){
            $(this).next().show();//飘过显示
        });
          $("#panel h5.head").bind("mouseout",function(){
             $(this).next().hide();//飘离隐藏
        })
    })
    </script>

    直接将事件简写成如下的方式也可以:

    <script type="text/javascript">
    $(function(){
        $("#panel h5.head").mouseover(function(){
            $(this).next().show();
        });
        $("#panel h5.head").mouseout(function(){
             $(this).next().hide();
        })
    })
    </script>
  • 相关阅读:
    重温CLR(七 ) 属性和事件
    重温CLR(六)方法和参数
    KMP算法
    Webstorm 2019最新激活码
    bash: cd: too many arguments 报错
    mongoDB线上数据库连接报错记录
    常见的 eslint 基本报错信息
    git 查看项目代码统计命令
    npm 删除指定的某个包以及再次安装
    vue.config.js常用配置
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/2678478.html
Copyright © 2011-2022 走看看