我的jQuery脚本无法运行......但我不确定为什么

时间:2014-10-01 06:13:50

标签: jquery html css jquery-hover

首先我知道这可以用CSS完全实现,但我最近学习了jQuery,虽然我会通过jQuery做一些破解,而不是帮助提高我的技能。

我试图这样做,当我将鼠标移到图像上时,它会变成一半不透明......我知道它应该很简单。但我想我一定错过了什么 我的标记是<img class="port-item-img" src="..."> 我的剧本是

    $(document).ready(function(){
        $(".port-item-img").hover(function() {
                $(this).css("opacity", "0.5");
            };
        );
    });

这不应该有用吗?

4 个答案:

答案 0 :(得分:0)

这应该有效

 $(document).ready(function(){
    $(".port-item-img").hover(function() {
            $(this).css("opacity", "0.5");
        });
 });

您为;

添加了}

答案 1 :(得分:0)

你有一个额外的分号。删除它,并确保包含jQuery和具有正确URL的图像。

$(document).ready(function () {
    $(".port-item-img").hover(function () {
        $(this).css("opacity", "0.5");
    }); //<--- Here was an extra ; 
});

DEMO

答案 2 :(得分:0)

$(document).ready(function(){
    $(".port-item-img").hover(function() {
            $(this).css("opacity", "0.5");
        }; // extra ;
    );
});

答案 3 :(得分:0)

对于那些想知道....是一个wordpress问题,wordpress不允许$(document).ready(){};语法而是你需要使用jQuery(document).ready($){};

相关问题