让div的children一一出现
我正在尝试使用 jquery 制作一个基本的图像分发器。
我所做的:当我单击空图像时,它会被加载并显示。 演示
$(".pic").click(function() {
var src = $(this).attr('rel');
$(this).attr('src', src);
});
[编辑] 我想填充 .pile div 中的每个图像 src ,一一对应,每次我点击 时。
我知道我需要使用循环或类似的东西,但我对此感到不太舒服。感谢您的帮助。
我的 HTML 内容:
<div class="pile">
<img class="pic" rel="3.jpg" src=""/>
<img class="pic" rel="2.jpg" src=""/>
<img class="pic" rel="1.jpg" src=""/>
</div>
I am trying to make a basic image distributor using jquery.
What I have done: When I click on an empty image, it is loaded and displayed. Demo
$(".pic").click(function() {
var src = $(this).attr('rel');
$(this).attr('src', src);
});
[edit] I want to fill every image src in the the .pile div, one by one, each time I click on the <body>
.
I know I need to use a loop or something like that but I am not really confortable with that. Thank you for any help.
My HTML content:
<div class="pile">
<img class="pic" rel="3.jpg" src=""/>
<img class="pic" rel="2.jpg" src=""/>
<img class="pic" rel="1.jpg" src=""/>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太确定这就是你的意思,但这里是每当单击页面时每个图像一次出现一个的代码。
这假设您想要的图像位于 ID 为 Pile 的
标记中。
请注意,我将您的原始代码包装在
$(document).ready(function(){ .... });
中。您可能在本地测试这一点并且没有注意到,但是如果没有我添加的东西,您的页面有时只能工作。I'm not quite sure this is what you meant but here is the code to have each img appear one at a time whenever the page is clicked.
This assumes the images you want are in the
<div>
tag with the id of pile.Note that I wrapped your original code inside of
$(document).ready(function(){ .... });
. You were probably testing this locally and didn't notice, but without that thing I added your page would only sometimes work.你在谈论这样的事情吗?:
演示: http://jsfiddle.net/ xmQbq/1/
Are you talking about something like this?:
Demo: http://jsfiddle.net/xmQbq/1/