Web Developer显示我的JavaScript是有效的,但如果我运行该页面,这将不起作用。我尝试在jquery-color的网站上跟踪使用,但每次都返回属性id missing。我真的希望我在大学里学习JavaScript的时候能有一个更好的老师。他闪现了一下jQuery和JavaScript的大部分内容,但并没有真正地教它。
编辑#1:我修复了代码中的(this)错误,但仍然没有成功。
下面是jQuery的代码:
<script type="text/javascript">
        jQuery("li.site-links").hover(function(){
            jQuery(this).stop().animate({
                backgroundColor: "#000000"
            }, 1000 );
        });
    </script>和站点链接:http://lab.nmjgraphics.com
发布于 2013-01-30 15:43:53
试试这个:
jQuery(function(){
   jQuery("a.site-links").hover(function(){
        jQuery(this).closest('li').stop().animate({
            backgroundColor: "#000000"
        }, 1000 );
    },function(){
        jQuery(this).closest('li').stop().animate({
        backgroundColor: "transparent"
    }, 1000 );
    });
 });您可以尝试使用.parent('li')
或者试试这个:
jQuery(function(){
   jQuery("a.site-links").parent('li').hover(function(){
        jQuery(this).stop().animate({
            backgroundColor: "#000000"
        }, 1000 );
    },function(){
        jQuery(this).closest('li').stop().animate({
        backgroundColor: "transparent"
    }, 1000 );
    });
 });https://stackoverflow.com/questions/14598893
复制相似问题