jQuery 中的 unbind()方法函数

首页 / jQuery入门教程 / jQuery 中的 unbind()方法函数

unbind([type],[fn])方法的作用与bind相反,它从每个匹配的元素中删除绑定事件。

unbind( [type], [fn] ) - 语法

selector.unbind( [type], [fn] )

这是此方法使用的所有参数的描述-

  • type    -  一种或多种事件类型,以空格分隔。

  • fn       - 取消与每个匹配元素上的事件绑定的函数。

unbind( [type], [fn] ) - 示例

以下是一个简单的示例,简单说明了此方法的用法-

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {

            function aClick() {
               $("div").show().fadeOut("slow");
            }
				
            $("#bind").click(function () {
               $("#theone").click(aClick).text("Can Click!");
            });
				
            $("#unbind").click(function () {
               $("#theone").unbind('click', aClick).text("Does nothing...");
            });
				
         });
      </script>
		
      <style>
         button { margin:5px; }
         button#theone { color:red; background:yellow; }
      </style>
   </head>
	
   <body>
      <button id="theone">Does nothing...</button>
      <button id="bind">Bind Click</button>
      <button id="unbind">Unbind Click</button>
		
      <div style="display:none;">Click!</div>
   </body>
</html>

这将产生以下输出-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/events-unbind.html

来源:LearnFk无涯教程网

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

面试现场 -〔白海飞〕

深入浅出计算机组成原理 -〔徐文浩〕

网络编程实战 -〔盛延敏〕

Netty源码剖析与实战 -〔傅健〕

设计模式之美 -〔王争〕

现代C++编程实战 -〔吴咏炜〕

TensorFlow 2项目进阶实战 -〔彭靖田〕

结构写作力 -〔李忠秋〕

结构会议力 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)