[英]Can I use html tags in twitter-bootstrap popover data-content?
I'm using Twitter-Bootstrap within a Rails 3.1.3 application. 我在Rails 3.1.3应用程序中使用Twitter-Bootstrap。 I have numerous elements with popovers like:
我有许多元素与popovers如:
<a data-original-title="Quality" rel="popover" data-content="Did they do a good job? 5 for Really Nice, 4 for Good Enough, 3 for Average, 2 for Somewhat OK, 1 for Really Bad">Q</a>
I'd like to have an ordered list in the content section similar to: 我想在内容部分中有一个有序列表,类似于:
<OL reversed="reversed">
<LI> for Really Nice </LI>
<LI> for Good Enough </LI>
...
</OL>
Is there a simple way to do this without modifying the JavaScript? 有一种简单的方法可以在不修改JavaScript的情况下执行此操作吗? Whatever I try, the html code is displayed on the browser instead of being interpreted as such.
无论我尝试什么,html代码都会显示在浏览器上,而不是被解释为这样。
UPDATE UPDATE
Using the following code per David's suggestion 根据David的建议使用以下代码
link_to 'Q', '#', options: { data-original-title: "Quality", rel: 'popover', data-content: "Did they do a good job? <ol><li> for Really Nice </li><li>...</li></ol>".html_safe }
generates a syntax error with my setup. 使用我的设置生成语法错误。 I think this explains why: Ruby 1.9 hash with a dash in a key .
我认为这解释了原因: Ruby 1.9使用密钥破折号 。 So I'm using:
所以我正在使用:
<%= link_to 'Q', '#', options: { :"data-original-title" => "Quality", :rel => 'popover', :"data-content" => "Did they do a good job? <ol><li> for Really Nice </li></ol>".html_safe } %>
This doesn't work. 这不起作用。 It generates the following HTML:
它生成以下HTML:
<a href="#" options="{:"data-original-title"=>"Quality", :rel=>"popover", :"data-content"=>"Did they do a good job? <ol><li> for Really Nice </li></ol>"}">Q</a>
You need to create a popover instance that has the html
option enabled (place this in your javascript file after the popover JS code): 您需要创建一个启用了
html
选项的弹出框实例(在弹出的JS代码之后将其放在您的javascript文件中):
$('.popover-with-html').popover({ html : true });
Then the link syntax would be: 那么链接语法将是:
<%= link_to('Q', '#', :class => "popover-with-html", :title => "Quality", "data-content" => "#{some_content_object.html_safe}") %>
If you're dynamically generating the content, then you need to use html_safe
like David suggested so Rails doesn't escape the HTML code. 如果您正在动态生成内容,那么您需要像David建议的那样使用
html_safe
这样Rails就不会转义HTML代码。 Otherwise, you can just place HTML directly within that content attribute. 否则,您只需将HTML直接放在该内容属性中即可。
是的,你可以这样做,但是你需要在你的字符串上调用html_safe
(如果字符串是由Rails生成的)
link_to 'Q', '#', :title => "Quality", :rel => 'popover', "data-content" => "Did they do a good job? <ol><li> for Really Nice </li><li>...</li></ol>".html_safe }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.