首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么这个没有显示出来?

为什么这个没有显示出来?
EN

Stack Overflow用户
提问于 2013-01-30 15:42:15
回答 4查看 40关注 0票数 0

Web Developer显示我的JavaScript是有效的,但如果我运行该页面,这将不起作用。我尝试在jquery-color的网站上跟踪使用,但每次都返回属性id missing。我真的希望我在大学里学习JavaScript的时候能有一个更好的老师。他闪现了一下jQuery和JavaScript的大部分内容,但并没有真正地教它。

编辑#1:我修复了代码中的(this)错误,但仍然没有成功。

下面是jQuery的代码:

代码语言:javascript
运行
复制
<script type="text/javascript">
        jQuery("li.site-links").hover(function(){
            jQuery(this).stop().animate({
                backgroundColor: "#000000"
            }, 1000 );
        });
    </script>

和站点链接:http://lab.nmjgraphics.com

EN

Stack Overflow用户

回答已采纳

发布于 2013-01-30 15:43:53

试试这个:

代码语言:javascript
运行
复制
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')

或者试试这个:

代码语言:javascript
运行
复制
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 );
    });
 });
票数 0
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14598893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档