1

上下文说明(WordPress):我想检查我的 li 元素是否有一个名为“current-menu-item”的类,如果它确实希望它停止动画功能。如果它没有那个类继续动画。此脚本当前不工作。谢谢你的帮助。

$(document).ready(function ()
{
    $('.nav li a').hover(function() 
    {
        if ($(this).parentNode.hasClass('current-menu-item'))
        {
        alert('this item has the class of current-menu-item');
        }
        else
        {
        $(this).animate({color:'#3b3b3b'}, 300, 'linear');
        }
    }, 
    function() 
        {
        if ($(this).parentNode.hasClass('current-menu-item'))
        {
        // do nothing
        }
        else 
        {
            $(this).animate({color:'#999'}, 300, 'linear');
        }
    });
});
4

1 回答 1

3
if ($(this).parent().hasClass('current-menu-item'))

jQuery 对象没有parentNode属性。DOM 元素可以,但是返回的元素parentNode没有 jQuery 方法,如.hasClass(). 请改用 jQuery 的.parent()方法

于 2013-07-10T22:28:53.930 回答