假设我有一个组件,inputType="text",id ="cmp";
在一个js文件中,
$("input[type='text']").bind('keypress', function(e) {
//Case 1
});
在我的jsp文件中,
$("#cmp").keypress(function() {
//Case 2
});
现在我只需要删除一个按键事件。 是否可以删除从 js 文件注册的 id = "cmp"的按键事件。 但是我们不应该删除从 jsp 文件中注册的事件。
注意: 根据我的要求,我无法更改.js 文件。
最佳答案
您可以使用 jquery 方法的 off
来删除事件 Jquery OFf
The off() method removes event handlers that were attached with .on(). See the discussion of delegated and directly bound events on that page for more information. Specific event handlers can be removed on elements by providing combinations of event names, namespaces, selectors, or handler function names. When multiple filtering arguments are given, all of the arguments provided must match for the event handler to be removed.
$('#cmp').off('keypress');
关于javascript - 删除特定事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331932/