jquery如何获取某一元素的指定子元素

婷婷fyt1216 2015-10-14 06:15:45
我想获取如图的不确定个数的img标签下的src,应该怎么写呀?
...全文
5860 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
婷婷fyt1216 2015-10-15
  • 打赏
  • 举报
回复
引用 5 楼 xiaofanku 的回复:
[quote=引用 4 楼 u013549582 的回复:] [quote=引用 2 楼 cqrf2006 的回复:] $(“·upload_img”).find("img").each(function(){alert(this.src}});
function test(){ alert (。。。); } 我是想在这里面得到一个数组,存的是上传的每个图片的src内容,请问怎么写呀?[/quote] 你一点脑不动吗?

var srcArr=$(“.upload_img”).find("img").map(function(){
   return $(this).attr('src');
}).get();
[/quote] 我没有学过js.....
forwardNow 2015-10-14
  • 打赏
  • 举报
回复




<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>

<div id="preview" class="upload_preview">
<div id="uploadList_0" class="upload_append_list">
<a class="imgBox" href="#" >
<div class="uploadImg">
<img class="upload_image" src="http://img4.imgtn.bdimg.com/it/u=3973469564,2643885576&fm=15&gp=0.jpg" alt="">
</div>
</a>
</div>
<div id="uploadList_0" class="upload_append_list">
<a class="imgBox" href="#" >
<div class="uploadImg">
<img class="upload_image" src="http://img4.imgtn.bdimg.com/it/u=417571815,4029812825&fm=15&gp=0.jpg" alt="">
</div>
</a>
</div>
</div>

<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
<script>

// 1. 通过CSS选择器来定位所有<img>
var uploadImageList = $("#preview .imgBox .upload_image");

// 2. 获取所有<img>的src属性值,返回一个jQuery对象(包含所有的src属性值)
var uploadImageSrcList = uploadImageList.map( function() {
return this.src;
} );

// 3. 将此jQuery对象转化为JS数组
var uploadImageSrcArray = uploadImageSrcList.toArray();

console.info( uploadImageSrcArray, uploadImageSrcArray instanceof Array );


</script>
</body>
</html>
街头小贩 2015-10-14
  • 打赏
  • 举报
回复
引用 4 楼 u013549582 的回复:
[quote=引用 2 楼 cqrf2006 的回复:] $(“·upload_img”).find("img").each(function(){alert(this.src}});
function test(){ alert (。。。); } 我是想在这里面得到一个数组,存的是上传的每个图片的src内容,请问怎么写呀?[/quote] 你一点脑不动吗?

var srcArr=$(“.upload_img”).find("img").map(function(){
   return $(this).attr('src');
}).get();
婷婷fyt1216 2015-10-14
  • 打赏
  • 举报
回复
引用 2 楼 cqrf2006 的回复:
$(“·upload_img”).find("img").each(function(){alert(this.src}});
function test(){ alert (。。。); } 我是想在这里面得到一个数组,存的是上传的每个图片的src内容,请问怎么写呀?
婷婷fyt1216 2015-10-14
  • 打赏
  • 举报
回复
引用 1 楼 xiaofanku 的回复:
$('.upload_append_list').find(img)

alert出来的是这样的,并没有src的数组呀!
feng00~ 2015-10-14
  • 打赏
  • 举报
回复
$(“·upload_img”).find("img").each(function(){alert(this.src}});
街头小贩 2015-10-14
  • 打赏
  • 举报
回复
$('.upload_append_list').find(img)

87,955

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧