为生成的图像提供 ID/类
我有大约 10 张来自 flickr 的图片。目前,它们只是以图像形式出现,没有个人 ID 或班级名称。
所以我有:
<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" />
……等等。我想做的是:
<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 添加到图像中。每个人都需要有不同的风格。
有什么想法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用ajax的回调函数...
如果你有这样的东西,
use the callback function of your ajax...
if you have something like this,
您可以使用:
或:
其中
jQueryEl
是包装元素。或者,如果您有一组图像,您可能会发现attr
的函数选项很有帮助:这实际上类似于 attr 文档。
You can use:
or:
where
jQueryEl
is a wrapped element. Or, if you have a set of images, you might findattr
's function option helpful:This is actually similar to an example in the attr docs.
如果您想发布获取图像的代码,它可能可以更好地集成在那里。但是,您也可以在添加图像后添加此代码。让我们假设图像已添加到 id 为
flickr
的 div 中:就是这样!现在,每个图像将按顺序具有
image1
、image2
等作为id
。If you want to post the code that fetches the images, it probably could be better integrated there. However, you could also just add this code after the images have been added. Lets pretend the images are added to a div with the id of
flickr
:Thats it! Now each image will have
image1
,image2
, etc as theid
, in order.