1

jQuery を使用して他の要素にカーソルを合わせているときに要素の css を変更していますが、Chrome 開発者ツールでこのエラーが発生しています: 「Uncaught TypeError: Object .gearImg has no method '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);
    });

問題はどこだ?

ありがとう

4

3 に答える 3

3

これを試してください:デモ http://jsfiddle.net/VGAv8/

$行方不明--$これが何を読んでいるのかさらに知りたい場合はWhat is mean 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);
    });
于 2012-10-09T21:27:11.200 に答える
1

セレクターの前に$がありません

$('#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);
    });
于 2012-10-09T21:33:20.707 に答える
1

の前にjQuery/を入れてみてはどうですか?または _$('.gearImg')
jQuery('.gearImg')$('.gearImg')

于 2012-10-09T21:27:29.827 に答える