:[JQ权威指南]第十天:unbind()方法移除元素绑定事件

unbind()的功能是移除元素绑定的事件,其调用的语法格式如下:
unbind([type],[fn])

其中,参数type为移除的事件类型,fn为需要移除的事件处理函数。如果该方法没有参数,移除所有绑定的时间;如果带有参数type,移除该参数所指定的时间类型;如果带有参数fn,则值移除绑定时候指定的函数fn.

在页面中设置三个按钮,前两个按钮分别执行各自的时间,第三个按钮通过unbind方法移除所绑定的全部事件。即单击第三个按钮后,前两个按钮的事件将不会执行。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>移除事件</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../jquery-2.1.4.js" ></script>
<style type="text/css">
    body{ font-size:13px}
    .btn{border:#666 1px solid; padding:2px; width:80px;}
    div{ line-height:1.8em}
</style>
<script type="text/javascript">
    $(function(){
        function oClick(){
            $("#divTip").append("<div>按钮二的单击事件</div>");
        }
        $("input:eq(0)").bind("click",function(){
            $("#divTip").append("<div>按钮一的单击事件</div>");
            });
        $("input:eq(1)").bind("click",oClick);
        $("input:eq(2)").bind("click",function(){
            $("input").unbind("click",oClick);
            $("#divTip").append("<div>按钮二的绑定事件被取消</div>");
            });

    })
</script>
</head>
<body>
    <div>
        <input id="Button1"  type="button" value="按钮一" class="btn">
        <input id="Button2"  type="button" value="按钮二" class="btn">
        <input id="Button3"  type="button" value="删除事件" class="btn">
    </div>
    <div id="divTip" style="padding-top:10px"></div>
</body>
</html>
![这里写图片描述](https://img-blog.csdn.net/20150728144421675)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

厦门德仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值