返回信息流是这样,我使用bootstrap的for循环{% for item in images %},循环中包含<a href="#modal">,但是发现模态框总是得到第一组数据,这是为什么呢?
求达人指点一二~~[ema1][ema1][ema1]
解决方法是:
在for循环中动态指定id即可,然后在modal的定义中指定刚才的id。
{% for image in images %}
<!-- PORTFOLIO IMAGE 1 -->
<div class="col-md-4">
<div class="grid mask">
<figure>
<img class="img-responsive" src="/static/uploads/{{ image }}" alt="">
<figcaption>
<a data-toggle="modal" href="#myModal" class="btn btn-primary btn-lg">see</a>
</figcaption><!-- /figcaption -->
</figure><!-- /figure -->
</div><!-- /grid-mask -->
</div><!-- /col -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<p><img class="img-responsive" src="/static/uploads/{{ image }}" alt=""></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endfor %}
这是一条镜像帖。来源:北邮人论坛 / python / #5394同步于 2015/3/4
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Python机器人发帖
【已解决】能否问个flask前端的事,传数据给模态框
buptmuye
2015/3/4镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
是这样阿,谢谢。
那如果想得到不同的,要如何做呢?
因为这里的情况是for循环,是动态的,所以能否使用相同的modal的id,来展现不同的东西
【 在 Chon 的大作中提到: 】
: 因为每个modal都用了同样的id
The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).
http://www.w3schools.com/tags/att_global_id.asp
所以你必须使用不同的id。
【 在 buptmuye 的大作中提到: 】
: 是这样阿,谢谢。
: 那如果想得到不同的,要如何做呢?
: 因为这里的情况是for循环,是动态的,所以能否使用相同的modal的id,来展现不同的东西
恩,涨姿势了,谢谢你
【 在 Chon (【意涵团】【奸商】葱先森) 的大作中提到: 】
: The id attribute specifies a unique id for an HTML element (the value must be unique within the HTML document).
: http://www.w3schools.com/tags/att_global_id.asp
: 所以你必须使用不同的id。
通过『我邮2.0』发布