0

我正在使用这样的代码为 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]: "&amp;lt;div class=&quot;ui-wrapper ui-draggable&quot; style=&quot;overflow: hidden; position: absolute; width: 128px; height: 128px; top: 223.1111125946045px; left: 243.11111450195313px; margin: 0px;&quot;&amp;gt;&amp;lt;img id=&quot;link1&quot; style=&quot;position: static; margin: 0px; resize: none; zoom: 1; display: block; height: 128px; width: 128px;&quot; src=&quot;http://i.imgur.com/cou2Yxj.png &quot; class=&quot;ui-resizable&quot;&amp;gt;&amp;lt;div class=&quot;ui-resizable-handle ui-resizable-e&quot; style=&quot;z-index: 90;&quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class=&quot;ui-resizable-handle ui-resizable-s&quot; style=&quot;z-index: 90;&quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class=&quot;ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se&quot; style=&quot;z-index: 90;&quot;&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img class=&quot;icon-layer-up icon-on-img&quot; src=&quot;/assets/icon_layer_up.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-layer-down icon-on-img&quot; src=&quot;/assets/icon_layer_down.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-trash1 icon-on-img&quot; src=&quot;/assets/icon_trash.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-copy-el icon-on-img&quot; src=&quot;/assets/icon_copy.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-layer-up icon-on-img&quot; src=&quot;/assets/icon_layer_up.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-layer-down icon-on-img&quot; src=&quot;/assets/icon_layer_down.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-trash1 icon-on-img&quot; src=&quot;/assets/icon_trash.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;img class=&quot;icon-copy-el icon-on-img&quot; src=&quot;/assets/icon_copy.png&quot; style=&quot;z-index: 2;&quot;&amp;gt;&amp;lt;/div&amp;gt;"

所以我在开头和结尾都有双引号,当我使用这样的代码将其放入 html 时,我将行 HTML 代码作为幻灯片的内容(它们被视为文本):

 for (var i = 0; i < slides.length; i++) {
          slides[i].innerHTML = contentObject["content[" + i + "]"];
          slides[i].style.backgroundImage = contentObject["background[" + i + "]"];
      }

我怎样才能逃避这个报价?

4

1 回答 1

1

html_safe是您需要在此处添加的内容:

parent.$("#data-store").data("content[<%=n%>]", '<%= @content[n.to_s].squish.html_safe %>');
于 2013-10-30T13:57:06.227 回答