【发布时间】:2016-02-02 16:17:00
【问题描述】:
我不想一次显示所有图像,因为它只会使页面设计混乱。我想单击引导 btn 组中的一个按钮,然后显示相应的图像。不是 javascript/jquery 人,所以我需要一点帮助。
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-default">Front</button>
<button type="button" class="btn btn-default">Back</button>
<button type="button" class="btn btn-default">Left</button>
<button type="button" class="btn btn-default">Right</button>
</div>
<div class="front-product-img">
<% front = @product['colors'][0]['images'].find{|img| img['label'] == 'Front'} %>
<%= image_tag front['url'], class: 'img-responsive' if front.present? %>
</div>
<div class="back-product-img">
<% back = @product['colors'][0]['images'].find{|img| img['label'] == 'Back'} %>
<%= image_tag back['url'], class: 'img-responsive' if back.present? %>
</div>
<div class="left-product-img">
<% left = @product['colors'][0]['images'].find{|img| img['label'] == 'Left'} %>
<%= image_tag left['url'], class: 'img-responsive' if left.present? %>
</div>
<div class="right-product-img">
<% right = @product['colors'][0]['images'].find{|img| img['label'] == 'Right'} %>
<%= image_tag right['url'], class: 'img-responsive' if right.present? %>
</div>
【问题讨论】:
标签: javascript jquery ruby-on-rails twitter-bootstrap