jQuery - 获取div中的所有src图片并放入字段 [英] jQuery - get all src of images in div and put into field

查看:612
本文介绍了jQuery - 获取div中的所有src图片并放入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想修改本教程以我的要求,但有一个问题给我。我是一名jQuery初学者,我想从规范div中获取所有图像源并将其放入字段中。有一个变量图像,它是字段并包含一些图像,但我不想从div中获取所有图像源并将它们放入字段图像中。我知道这并不复杂,但我真的不知道该怎么做。



来源位于 http://jsfiddle.net/s5V3V/36/

这是变量 image 源于jsfiddle,我想从div中填充,而不是我现在在那里:

  images = ['http://kimjoyfox.com/blog/wp-content/uploads/drwho8.jpg',
'http://kimjoyfox.com/blog/wp-content/uploads/drwho7.jpg',
'http://kimjoyfox.com/blog/wp-content/uploads/drwho6.jpg',
'http://kimjoyfox.com/blog/wp-content/uploads/drwho5.jpg' ,
'http://kimjoyfox.com/blog/wp-content/uploads/drwho4.jpg',
'http://kimjoyfox.com/blog/wp-content/uploads/drwho3。 jpg',
'http://kimjoyfox.com/blog/wp-content/uploads/dr-whos-tardis.png',
'http://kimjoyfox.com/blog/wp- content / uploads / drwho9.jpg',
'http://kimjoyfox.com/blog/wp-conten吨/上传/ drwho1.jpg];

感谢您的进步。

解决方案

在dom准备试试

  var images = $('。thumbnailArrows')。children('img ').map(function(){
return $(this).attr('src')
})。get()


I want to modified this tutorial to my requirements but there is one problem to me. I'm a beginner with jQuery and I would like to get all image sources from specifïc div and put them into field. There is a variable images which is field and contain some images but I want instead of this get all image sources from div and put them into field images. I know that isn't such a complicated but I don't really know how to do it.

The source is here http://jsfiddle.net/s5V3V/36/

This is the variable image from source on jsfiddle which I want fill from div instead what I have there now:

images = ['http://kimjoyfox.com/blog/wp-content/uploads/drwho8.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho7.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho6.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho5.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho4.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho3.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/dr-whos-tardis.png',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho9.jpg',
    'http://kimjoyfox.com/blog/wp-content/uploads/drwho1.jpg'];

Thanks advance.

解决方案

In dom ready try

var images = $('.thumbnailArrows').children('img').map(function(){
    return $(this).attr('src')
}).get()

这篇关于jQuery - 获取div中的所有src图片并放入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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