Jquery如何禁用特定选择器的函数
Jquery how to disable functions for specific selectors?
这是我的Jquery标签菜单:
var current = $('li.selected');
$('li.selected #submenu').css("display", "block").addClass('lihovered');
current.addClass('lihovered');
$("ul#ulmenu li").hover(function() { //Hover over event on list item
$(this).find("#submenu").show(); //Show the subnav
$(this).addClass('lihovered');
current.removeClass('lihovered');
} , function() { //on hover out...
$(this).find("#submenu").hide(); //Hide the subnav
$(this).removeClass('lihovered');
current.addClass('lihovered');
});
$("ul#submenu").hover(function() { //Hover over event on list item
$(this).show(); //Show the subnav
$(this).parent("li").addClass('lihovered');
$(this).parent("li").find('a').addClass('lihovereda');
} , function() { //on hover out...
$(this).find("#submenu").hide(); //Hide the subnav
$(this).parent("li").removeClass('lihovered');
$(this).parent("li").find('a').removeClass('lihovereda');
current.addClass('lihovered');
});
问题是,当悬停悬停时,被选中的袋子被移除。因此,我想禁用此功能:
$("ul#ulmenu li").hover(function() { //Hover over event on list item
$(this).find("#submenu").show(); //Show the subnav
$(this).addClass('lihovered');
current.removeClass('lihovered');
} , function() { //on hover out...
$(this).find("#submenu").hide(); //Hide the subnav
$(this).removeClass('lihovered');
current.addClass('lihovered');
});
对于$('li.selected');
我也有这个问题,当悬停悬停在菜单中的另一个li元素被选中的子菜单被隐藏。因此,我想禁用此功能:
$("ul#submenu").hover(function() { //Hover over event on list item
$(this).show(); //Show the subnav
$(this).parent("li").addClass('lihovered');
$(this).parent("li").find('a').addClass('lihovereda');
} , function() { //on hover out...
$(this).find("#submenu").hide(); //Hide the subnav
$(this).parent("li").removeClass('lihovered');
$(this).parent("li").find('a').removeClass('lihovereda');
current.addClass('lihovered');
});
for $('li.selected #submenu');
问题是#li。当鼠标悬停在子菜单或li元素上时,选中的#submenu被隐藏。这是不应该的。
更新,我已经尝试过这个,但它是(不)工作:
$("ul#ulmenu li").hover(function() { //Hover over event on list item
if($(this).hasClass('selected')) {
} else {
$(this).find("#submenu").show(); //Show the subnav
$(this).addClass('lihovered');
current.removeClass('lihovered');
}
} , function() { //on hover out...
$(this).find("#submenu").hide(); //Hide the subnav
$(this).removeClass('lihovered');
current.addClass('lihovered');
});
但是if else语句非常难看。
使用not()方法:http://api.jquery.com/not/
$("ul#ulmenu li").not('.selected').hover(function() {
and:not选择器http://api.jquery.com/not-selector/
$('li:not(.selected) ul#submenu').hover(function() {
相关文章:
- 如何将jquery函数链接到vanilla选择器
- jQuery选择器不识别任何动态创建的HTML输入函数
- 函数在日期选择器中选择日期之前触发
- 原型中漂亮的代码,如何省略'不是函数'空结果选择器上的错误
- 为什么JQueryshow()函数只对带有选择器的一个(而不是所有)元素起作用
- 日期选择器更改事件抛出”;TypeError:字符串不是函数;
- 使用元素选择器向Object添加函数
- 用于多个from输入的JQuery日期选择器函数
- 为什么jQuery选择器函数与原生DOM方法相比如此缓慢
- Javascript数字选择器函数
- 如何向 Javascript 表添加一行,其中包含包含 jQuery 中的日期选择器函数的单元格
- 无法停止/删除/销毁日期计时器选择器函数 (jQuery)
- JsPlumb - 将自己的选择器函数添加到动态锚点
- 如何将颜色选择器函数集成到动态文本字段中
- 两个连续的java脚本日期选择器函数
- 日期表没有'如果我放了日期选择器函数,它就根本不起作用
- 按属性值的数组选择器函数
- Jquery选择器函数参数
- 如何在 Observable.bindCallback 方法中使用 RXJS 选择器函数
- jQuery日期选择器函数