Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
Javascript 如何使用jquery获取img标记的src_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何使用jquery获取img标记的src

Javascript 如何使用jquery获取img标记的src,javascript,jquery,html,Javascript,Jquery,Html,我有一个HTML,如下所示: <ul class="thumbnails"> <li><a class="thumbnail" href="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_1-500x500.jpg" title="Canon EOS 5D"><img src="http://localhost/upload/image/cache/catalog/dem

我有一个HTML,如下所示:

<ul class="thumbnails">
    <li><a class="thumbnail" href="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_1-500x500.jpg" title="Canon EOS 5D"><img src="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_1-228x228.jpg" title="Canon EOS 5D" alt="Canon EOS 5D"></a></li>
    <li class="image-additional"><a class="thumbnail" href="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_2-500x500.jpg" title="Canon EOS 5D"> <img src="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_2-74x74.jpg" title="Canon EOS 5D" alt="Canon EOS 5D"></a></li>
    <li class="image-additional"><a class="thumbnail" href="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_3-500x500.jpg" title="Canon EOS 5D"> <img src="http://localhost/upload/image/cache/catalog/demo/canon_eos_5d_3-74x74.jpg" title="Canon EOS 5D" alt="Canon EOS 5D"></a></li>
</ul>

它给出了
a标签的
href
,但是我想要在
a标签之后的img标签的src
我应该做什么修改?

图像是
缩略图的子元素。您需要使用:

$('.thumbnail').find('img').attr("src");
更改图像的SRC:

 $('.thumbnail').find('img').attr("src", newSRC);

图像是
缩略图的子元素。您需要使用:

$('.thumbnail').find('img').attr("src");
更改图像的SRC:

 $('.thumbnail').find('img').attr("src", newSRC);

要获取图像的
src
属性值,需要请求
src
属性,而不是
href
属性

要获取元素的子元素,请使用
parent>child

就你而言:

$('.thumbnail > img').attr('src');

要获取图像的
src
属性值,需要请求
src
属性,而不是
href
属性

要获取元素的子元素,请使用
parent>child

就你而言:

$('.thumbnail > img').attr('src');

您可以使用

$('.thumbnail img').attr('src');

您可以使用

$('.thumbnail img').attr('src');

您需要src值,然后获取
.attr('src')
而不是
.attr(“href”)
。您需要src值,然后获取
.attr('src')
而不是
.attr(“href”)
。如果我想使用jquery更改此src的值,那么我如何?@rohitashvinghal
$('.thumbnail')。查找('img').attr(“src”),'myNewURLHERE'))
如果我想使用jquery更改此src的值,那么我如何才能?@RohitashvSinghal
$('.thumbnail').find('img').attr('src','myNewURLHERE')