我有一个动态创建的div数组..我可以单独访问它们并相应地更改某些属性。问题是如何实现它,一旦我更改下一个div的属性,前一个进入初始状态?我在代码中写了这个问题..
<% @relevant_videos.each_with_index do |vid, idx| %>
<%= image_tag("http://img.youtube.com/vi/#{vid.content}/0.jpg", :id => "img_div_#{idx}", :class => "span2 thumb", :style => "margin-bottom: 10px; margin-top: 10px") %>
<div id="vid_vid_<%=idx%>" style="display: none"> <%= vid.id %></div>
<% end %>
<script>
var ids = "<%= @node.parent_relation.videos.length %>";
console.log(ids);
var div_arr = [];
var img_arr = [];
var vid_id = 0;
for( i=0; i < parseInt(ids); i++){
var x = String("vid_vid_"+String(i));
var y = String("img_div_"+String(i));
div_arr.push(x);
img_arr.push(y);
}
for ( i=0; i < parseInt(ids); i++){
var vst = '#'+String(img_arr[i]);
var dst = '#'+String(div_arr[i]);
$(function() {
$(vst).click({dst: dst}, function(event){
var vid_id = $(event.data.dst).html();
$.post("/nodes/iframize/", {video_id: vid_id});
//HERE IS THE SOLUTION I AM USING, NOT SURE ABOUT IT'S EFFECTIVENESS..
var old_div = $("#data_div").data("mydiv");
$(old_div).css("background","rgba(255,255,255,0.3)", "border-radius", "8px");
$(this).css("background","rgba(255,255,50,0.5)", "border-radius", "8px");
$("#data_div").data("mydiv", this);
});
})
}
</script>
!
谢谢!