为生成的图像提供ID/类别 [英] Give ID/Class to generated images

查看:95
本文介绍了为生成的图像提供ID/类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10张左右的图片来自flickr.目前,它们只是以没有单独ID或类名的图像形式出现.

I have 10 or so images coming in from flickr. At the moment they just come in as images with no individual ID or Class names.

所以我有

<img src="images/01.jpg" width="300" height="273" />
<img src="images/01.jpg" width="300" height="273" />
<img src="images/01.jpg" width="300" height="273" />
<img src="images/01.jpg" width="300" height="273" />

...等等.我想做的是:

...and so on. What I want to do is have:

<img id="image1" src="images/01.jpg" width="300" height="273" />
<img id="image2" src="images/01.jpg" width="300" height="273" />
<img id="image3" src="images/01.jpg" width="300" height="273" />
<img id="image4" src="images/01.jpg" width="300" height="273" />

但是因为它们是通过jQuery而不是手动引入的,所以我不确定如何将这些ID依次添加到图像中.每种样式都需要不同.

But because they are being brought in via jQuery, and not manually, I'm unsure how to add these ID's, in order, to the images. Each needs to be styled differently.

有什么想法吗?

推荐答案

使用ajax的回调函数...

use the callback function of your ajax...

如果您有这样的事情,

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?", function (data) {
    $.each(data.items, function (i, item) {
        $("<img/>").attr({"src":item.media.m, 'id': 'images' + i}).appendTo("#images");
    });
});

这篇关于为生成的图像提供ID/类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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