我正在使用这样的代码为 jquery 放置 rails 参数:
<% @num_slides.times do |n| %>
parent.$("#data-store").data("background[<%=n%>]","<%= @background[n.to_s] %>" );
parent.$("#data-store").data("content[<%=n%>]", '<%= @content[n.to_s].squish %>');
<% end %>
它适用于背景,但它呈现的内容如下:
content[0]: "&lt;div class="ui-wrapper ui-draggable" style="overflow: hidden; position: absolute; width: 128px; height: 128px; top: 223.1111125946045px; left: 243.11111450195313px; margin: 0px;"&gt;&lt;img id="link1" style="position: static; margin: 0px; resize: none; zoom: 1; display: block; height: 128px; width: 128px;" src="http://i.imgur.com/cou2Yxj.png " class="ui-resizable"&gt;&lt;div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"&gt;&lt;/div&gt;&lt;div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"&gt;&lt;/div&gt;&lt;div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"&gt;&lt;/div&gt;&lt;img class="icon-layer-up icon-on-img" src="/assets/icon_layer_up.png" style="z-index: 2;"&gt;&lt;img class="icon-layer-down icon-on-img" src="/assets/icon_layer_down.png" style="z-index: 2;"&gt;&lt;img class="icon-trash1 icon-on-img" src="/assets/icon_trash.png" style="z-index: 2;"&gt;&lt;img class="icon-copy-el icon-on-img" src="/assets/icon_copy.png" style="z-index: 2;"&gt;&lt;img class="icon-layer-up icon-on-img" src="/assets/icon_layer_up.png" style="z-index: 2;"&gt;&lt;img class="icon-layer-down icon-on-img" src="/assets/icon_layer_down.png" style="z-index: 2;"&gt;&lt;img class="icon-trash1 icon-on-img" src="/assets/icon_trash.png" style="z-index: 2;"&gt;&lt;img class="icon-copy-el icon-on-img" src="/assets/icon_copy.png" style="z-index: 2;"&gt;&lt;/div&gt;"
所以我在开头和结尾都有双引号,当我使用这样的代码将其放入 html 时,我将行 HTML 代码作为幻灯片的内容(它们被视为文本):
for (var i = 0; i < slides.length; i++) {
slides[i].innerHTML = contentObject["content[" + i + "]"];
slides[i].style.backgroundImage = contentObject["background[" + i + "]"];
}
我怎样才能逃避这个报价?