从单个 Div 元素中删除单击事件
Remove the click event from a single Div element
我已经为父div内的所有div添加了一个鼠标向下处理程序,如下所示:
$productContainer.children(".button").on('mousedown', function(){
var index = $(this).index();
console.log("Clicked button at " + index);
// this doesnt work
$(this).removeAttr('mousedown');
});
现在我想在单击按钮后删除该特定div 的鼠标向下处理程序。我该怎么做?删除attr mousedown
似乎不起作用。
使用 off
方法:
$productContainer.children(".button").on('mousedown', function(){
var index = $(this).index();
console.log("Clicked button at " + index);
$(this).off('mousedown');
});
更多信息: http://api.jquery.com/off/
您也可以改用 one
方法。它将在第一次触发事件处理程序时自动删除它:
$productContainer.children(".button").one('mousedown', function(){
var index = $(this).index();
console.log("Clicked button at " + index);
});
更多信息: http://api.jquery.com/one/
而不是 :
$(this).removeAttr('mousedown');
用:
$(this).unbind('mousedown');
或
$(this).off('mousedown');
使用.off
说明:删除事件处理程序。
$productContainer.children(".button").off('mousedown');
$productContainer.children(".button").on('mousedown', function(){
var index = $(this).index();
console.log("Clicked button at " + index);
// this doesnt work
$(this).removeAttr('mousedown');
});
相关文章:
- 删除确认对话框在第一次单击时不起作用
- 如果30秒未单击,请应用CSS一次,将其删除,然后重新迭代
- 主体单击删除功能上的输入框宽度
- 兰吉 |如何在 span 标签上使用单击事件删除突出显示的文本
- 如何删除父表行时;删除“;在React JS中单击按钮
- button.单击两次删除附加操作后不工作
- 单击删除下拉子菜单
- 单击文本时删除文本框的默认数据
- 在显示/隐藏中单击时删除的文本
- 分配和删除单击事件
- 正在删除单击问题上的活动类
- 从单个 Div 元素中删除单击事件
- 在 angularjs 中使用删除单击的元素和范围
- 在 Jquery 中通过单击/单击删除单击的类
- 如何删除单击的控件上的特定类
- 删除单击“新建”按钮后添加的类
- 在javascript中从数组中删除单击的项
- 如何从锚点链接中删除单击事件
- 取消遮挡点击不'在我的情况下,无法删除单击事件
- 单击后立即删除单击事件处理程序