使用jQuery获取每个图像的源代码 [英] Get source of each image in div with jQuery

查看:93
本文介绍了使用jQuery获取每个图像的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图通过一个特定的div进行循环(目标是一个ID),并返回其中的两个图像的来源。这是我的HTML:

 < div id =container> 
< div class =row selectedid =one>< img src =onei.png>< img src =twoi.png>< / div>
< div class =rowid =two>< img src =onei1.png>< img src =twoi2.png>< / div>
< / div>

以下是我的循环:

<$ p $($'code $>'$'$'$'$'$'$'$'$'$'$'$'$'$'$'$' (this).attr('src'))
});
}

我似乎无法找出为什么这不起作用。不应该通过我的目标div中的每个图像循环并提醒源代码?

解决方案

也许类似于

  function loop(){
alert()
$('#container .row.selected img')。each函数(){
alert($(this).attr('src'))
});
}

您忘记了 on row


I'm trying to do a seemingly simple loop, but I keep running into issues.

I'm trying to loop through a specific div (targeted by an ID), and return the source of the two images inside of it. Here is my HTML:

<div id="container">
   <div class="row selected" id="one"><img src="onei.png"><img src="twoi.png"></div>
   <div class="row" id="two"><img src="onei1.png"><img src="twoi2.png"></div>
 </div>

And here is my loop:

function loop() {
    alert()
    $('#container row.selected img').each(function() {
        alert($(this).attr('src'))
    });
}

I can't seem to find out why this isn't working. Shouldn't this loop through each image in my targeted div and alert the source?

解决方案

maybe something like

function loop() {
    alert()
    $('#container .row.selected img').each(function() {
        alert($(this).attr('src'))
    });
}

you forgot the . on row

这篇关于使用jQuery获取每个图像的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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