[英].unbind() is not working on event.preventDefault()
I have a responsive Javascript file that is working successfully on unbinding basic jQuery functions. 我有一个响应性Javascript文件,该文件在解除对jQuery基本功能的绑定方面能成功工作。
When the browser is set to be in tablet, the navigation becomes toggled based on click, therefore I disable the linking to any li elements that have a ul. 当浏览器设置为平板电脑时,导航将基于单击切换,因此我禁用了链接到具有ul的任何li元素的功能。
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').on('click', function(event) {
event.preventDefault();
});
Then when the browser is sized above the tablet constraint, I am attempting to reenable the linking functionality with this (I have tried 3 different ways): 然后,当浏览器的大小超出平板电脑的限制时,我试图以此重新启用链接功能(我尝试了3种不同的方式):
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').unbind('on');
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').unbind('click');
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').on('click', function(event) {
return true;
});
Please let me know if there is anything else I can provide that might be helpful 请让我知道我是否还有其他可以提供的帮助
I was able to find the solution to my own problem here. 我可以在这里找到自己的问题的解决方案。 Thought I would post just in case someone else has a similar issue.
以为我会发布,以防万一有人遇到类似问题。
My responsive JavaScript has 2 functions per screen size. 我的自适应JavaScript每个屏幕尺寸都有2个功能。 I had something like this:
我有这样的事情:
function tabletInit() {
// add jQuery that is supposed to fire within these constraints
function mobileNavInit() {
var submenus = $('.main-navigation .children');
submenus.each(function() {
var parentLink = $(this).prev(),
parentHref = parentLink.attr('href'),
overview = '<li class="overview"><a href="'+parentHref+'">Overview</a></li>';
$(overview).prependTo($(this));
});
}
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').on('click', function(event) {
event.preventDefault();
});
}
function tabletClear() {
// undo or 'unbind()' anything that should be cancelled out if tablet is sized above
$(overview)unbind('prependTo');
$('.main-navigation .menu > ul > li > a, .main-navigation .menu > ul > li > ul > li:has(ul) > a').unbind('click');
}
The interference was one the unbinding of the overview function. 干扰是概述功能的解除约束之一。 Though the unbinding was performing as needed, it ended up interfering with some of the other JavaScript.
尽管解除绑定的操作符合需要,但最终干扰了其他一些JavaScript。 So I simply changed it to:
所以我只是将其更改为:
$('.overview, .overview2').remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.