Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery find(';img';).attr(';src';)不起作用_Jquery - Fatal编程技术网

jQuery find(';img';).attr(';src';)不起作用

jQuery find(';img';).attr(';src';)不起作用,jquery,Jquery,以下代码将不起作用: find('img').attr('src') 我希望将鼠标悬停在旁边区域,并打开/关闭图像更改 HTML <aside style="width:200px;height:300px;text-align:center;"> <img class="img" src="imgs/photo_off.png" alt="" > </aside> 不能像这样给函数调用语句赋值。它应该抛出一个错误,如 未捕获引用错误:赋值中的左侧无效

以下代码将不起作用:

find('img').attr('src')

我希望将鼠标悬停在旁边区域,并打开/关闭图像更改

HTML

<aside style="width:200px;height:300px;text-align:center;">
  <img class="img" src="imgs/photo_off.png" alt="" >
</aside>

不能像这样给函数调用语句赋值。它应该抛出一个错误,如

未捕获引用错误:赋值中的左侧无效

使用的setter版本


不能像这样给函数调用语句赋值。它应该抛出一个错误,如

未捕获引用错误:赋值中的左侧无效

使用的setter版本

$("aside").hover(
    function () {
        $(this).find('img').attr('src') = $(this).find('img').attr('src').replace("_off", "_on");
    },
    function () {
        $(this).find('img').attr('src') = $(this).find('img').attr('src').replace("_on", "_off");
    }
);
$(this).find('img').attr('src', $(this).find('img').attr('src').replace("_off", "_on"));
$("aside").hover(function () {
    $(this).find('img').attr('src', function (i, src) {
        return src.replace("_off", "_on");
    })
}, function () {
    $(this).find('img').attr('src', function (i, src) {
        return src.replace("_on", "_off");
    })
});
$(this).find('img')[0].src = $(this).find('img').attr('src').replace("_off", "_on");