【问题标题】:Is it valid to put div tags in title="" field将div标签放在title=""字段中是否有效
【发布时间】:2013-06-18 15:11:29
【问题描述】:

这对工具提示有效吗?出于某种原因,我认为在标题字段中添加 div 无效。

<div class="graph_item tooltip" title="
    <div id='tooltip_inner_container'>
    <div id='title'>Ready Set Cook!</div>
        <strong>250 HEALTHY POINTS</strong>
            The Goal of Ready, Set, Cook! is to cook and log at least 1 recipe per week for 8 weeks. If you complete this challenge, You will 
             become eligible for prizes.<br /><br />
            Registration:
            May 7 - May 14<br />
            Duration: May 15 - June 6
    </div>
" style="width:100%; height:58px; left:0%; top:0%; background-color:#0073ad; background-image:url(images/a.jpg);">

【问题讨论】:

标签: html tooltip


【解决方案1】:

也不是一个有效的 XML,你不应该将节点放在属性中。

我建议使用类似的 html:

<div class="graph_item has-tooltip"  style="width:100%; height:58px; left:0%; top:0%;    background-color:#0073ad; background-image:url(images/a.jpg);">
  <div class="tooltip" id='tooltip_inner_container'>
    <div id='title'>Ready Set Cook!</div>
        <strong>250 HEALTHY POINTS</strong>
            The Goal of Ready, Set, Cook! is to cook and log at least 1 recipe per week for 8 weeks. If you complete this challenge, You will 
             become eligible for prizes.<br /><br />
            Registration:
            May 7 - May 14<br />
            Duration: May 15 - June 6
    </div>
  </div>
</div>

作为CSS: .has-tooltip .tooltip{ 显示:无; } .has-tooltip .tooltip:hover{ 显示:块; }

【讨论】:

  • 是普通字符串?只有几个
  • 如果您使用的是 jquery 工具提示,没问题吗?还是最好只在标题字段中使用文本?
  • 属性不是有效的 xml 节点容器,您无法预测浏览器将如何处理它,如果需要更复杂的文本作为工具提示,我将使用 jquery 工具提示解决方案
  • @bwoebi 的意思是,虽然它没有达到 OP 想要的效果,但它是有效的 HTML。
  • 是的,它是 jquery 工具提示
【解决方案2】:

是的,您的 HTML 是有效的(当然,如果您关闭 div)。

然而,这个title 属性的内容是不是(也不能是)HTML。是文字。

【讨论】:

  • @B--rian:这不是代码图像,而是文本图像,其中文本包含看起来像但不是代码的内容。这就是答案和图片的重点:显示title 属性中的 HTML 代码不会被解释为 HTML,而是文本。
猜你喜欢
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
  • 2013-04-29
  • 1970-01-01
  • 2014-01-31
  • 2014-06-29
  • 1970-01-01
  • 2011-07-27
相关资源
最近更新 更多