【问题标题】:getting an error message "Uncaught TypeError: Object .gearImg has no method 'css' "收到错误消息“Uncaught TypeError: Object .gearImg has no method 'css'”
【发布时间】:2012-10-10 05:33:20
【问题描述】:

我正在使用 jQuery 更改某些元素的 css,同时将鼠标悬停在其他元素上,我在 Chrome 开发人员工具中收到此错误: “未捕获的 TypeError:Object .gearImg 没有方法 'css'” 这是我的css代码:

.gearImg{
    position: absolute;
    z-index: 10;
    top: 2px;
    right: 10px;
    opacity: 0.5;

}

这是我的 jquery 代码:

 $('#settings_div').hover(function(){
        $(this).show();
        alert(('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5
    },
    function(){
        $(this).hide();
        ('.gearImg').css('opacity', 0.5);
    });

问题出在哪里?

谢谢

【问题讨论】:

    标签: jquery html css hover


    【解决方案1】:

    请试试这个:demo http://jsfiddle.net/VGAv8/

    $missing -- 如果您对$ 是什么感到进一步好奇,请阅读此What is the meaning of "$" sign in javascript

    休息应该适合原因:)

    代码

    $('#settings_div').hover(function(){
            $(this).show();
            alert($('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5
        },
        function(){
            $(this).hide();
            $('.gearImg').css('opacity', 0.5);
        });
    

    【讨论】:

      【解决方案2】:

      jQuery/$放在('.gearImg')前面怎么样?
      应该是jQuery('.gearImg')$('.gearImg')

      【讨论】:

        【解决方案3】:

        选择器前面缺少 $

        $('#settings_div').hover(function(){
                $(this).show();
                alert($('.gearImg').css('opacity')); //alerting to find the problem, should show 0.5
            },
            function(){
                $(this).hide();
                $('.gearImg').css('opacity', 0.5);
            });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-12-25
          • 1970-01-01
          • 1970-01-01
          • 2012-04-20
          • 2013-03-13
          相关资源
          最近更新 更多