unbind([type],[fn])方法的作用与bind相反,它从每个匹配的元素中删除绑定事件。
selector.unbind( [type], [fn] )
这是此方法使用的所有参数的描述-
type - 一种或多种事件类型,以空格分隔。
fn - 取消与每个匹配元素上的事件绑定的函数。
以下是一个简单的示例,简单说明了此方法的用法-
链接:https://www.learnfk.com/jquery/events-unbind.html
来源:LearnFk无涯教程网
<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>
这将产生以下输出-
这一章《jQuery - Events - unbind()方法 函数》你学到了什么?在下面做个笔记吧!做站不易,你的分享是对我们最大的支持
使用 Webpack 将 jQuery 公开给真实的 Window 对象