0

所以我创建了一个 erb 块,它遍历每个图像标签('.tagged')的坐标,然后在给定坐标处为每个图像显示'.tagged'。在这种特殊情况下,块会遍历 2 个图像,并且 .tagged 会显示在两个图像上,而不是每个受尊重的图像一个标签。这是因为 .each() 方法吗?

<div class="container">
<% if @new_manual.present? %>
<% @new_manual.steps.each do |step| %>
    <% i_connection = Contact.find(step.input_contact) %>

<span class="i_connection" data-pos-x="<%= i_connection.pos_x %>" data-pos-y="<%= i_connection.pos_y %>"  data-pos-width="<%= i_connection.pos_width %>" data-pos-height="<%= i_connection.pos_height %>"> </span>
<br>
<div class="image_panel">
    <%= image_tag(i_connection.image.image.url(:large)) %>
<div class='planetmap'></div>
</div>

<script type="text/javascript">
$(document).ready(function(){
$("span.i_connection").each(function() {
    var pos_width = $(this).data('pos-width');
    var pos_height = $(this).data('pos-height');
    var xpos = $(this).data('pos-x');
    var ypos = $(this).data('pos-y');

    $(".tagged_box").css("display","block");
    $(".tagged").css("border","5px solid red");

        $('.planetmap').append('<div class="tagged"  style="width:'+pos_width+'px;height:'+pos_height+'px;left:'+xpos+'px;top:'+ypos+'px;" ><div class="tagged_box" style="width:'+pos_width+'px;height:'+
            pos_height+'px;" ></div>')
});   //END OF SPAN.CONNECTION ITERATION
}); //END OF JQUERY
</script>   
<% end %>   
<% end %>
</div>
4

1 回答 1

0

将您的 javascript 块移到

<% @new_manual.steps.each do |step| %>

环形。

于 2013-07-22T03:06:59.697 回答