jQuery---事件操作

1.window.onload和document.ready的区别
当执行多个windows.onload时,页面加载完毕后只会执行最后一个windows.onload
执行多个document.ready时,会按顺序执行多个document.ready.
2.事件绑定
bind()函数

bind(type[,data,],fn);

//案例:事件绑定完成闭合
<script type="text/javascript">
    $(document).ready(function(){
        $(".he").bind("mouseover",function(){
            $(this).next().show();
        });
        $(".he").mouseout(function(){
            $(this).next().hide();
        });
    });
  </script>

3.合成事件
hover(over,out) 函数
当鼠标放上执行第一个函数,当鼠标离开,执行第二个函数

<script type="text/javascript">
    $(document).ready(function(){
        $(".he").hover(function(){
            $(this).next().show();
            $(this).addClass("green");
        },function(){
            $(this).next().hide();
            $(this).removeClass("green");
        })
    });
  </script>

toggle(fn1,fn2,fn3…)函数
点击了第一个匹配元素,则会触发第一个函数,再次点击会触发第二个,再点击会触发第三个…

<script type="text/javascript">
    $(document).ready(function(){
        $(".he").toggle(function(){
            $(this).next().show();
            $(this).addClass("green");
        },function(){
            $(this).next().hide();
            $(this).removeClass("green");
        })
    });
  </script>

4.移除事件
unbind(“click”) 移除点击事件

$("#i01").click(function(){
        $(".he").unbind("click");
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值