尝试使用jquery动态更改img时出现语法错误 [英] syntax error while trying to dynamically change imgs using jquery

查看:56
本文介绍了尝试使用jquery动态更改img时出现语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网页上的主照片更改为鼠标悬停时突出显示的照片.下面的代码导致一个错误,表明我的引号有问题.这可能是什么问题?

I'm trying to change the main photo on my webpage to one that is highlighted on mouseover. The code below results in a bug saying that there is something wrong with my quotation marks. What could be the problem here?

    $(document).ready(function(){
    $(".colorDiv").mouseover(function(){
        $(this).css("border", "2px solid #2F4F4F");
        $(".mPhoto['src="photos/WP_20140621_002.jpg"']").attr("src", ".colorImg");
    });
    $(".colorDiv").mouseout(function(){
        $(this).css("border", "none");
    })
});

.colorImg是我要用来更改原始图像的img的类

.colorImg is the class of the imgs that I want to change original image with

.mPhoto是我要更改的主照片类

.mPhoto is class of main photo that I want to change

推荐答案

您的问题是引号. 如果我理解但您正在尝试这样做,那就是:

Your problem are the quotes. If I understood but you are trying to do, this is :

$(".mPhoto").attr("src", "photos/WP_20140621_002.jpg");

这篇关于尝试使用jquery动态更改img时出现语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆