Can I use html tags in twitter-bootstrap popover data-content?

前端 未结 2 1889
-上瘾入骨i
-上瘾入骨i 2020-12-23 21:31

I\'m using Twitter-Bootstrap within a Rails 3.1.3 application. I have numerous elements with popovers like:



        
相关标签:
2条回答
  • 2020-12-23 22:08

    Yes, you can do that, but you need to call html_safe on your string (if the string is generated by 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 }
    
    0 讨论(0)
  • 2020-12-23 22:09

    You need to create a popover instance that has the html option enabled (place this in your javascript file after the popover JS code):

    $('.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. Otherwise, you can just place HTML directly within that content attribute.

    0 讨论(0)
提交回复
热议问题