简体   繁体   English

如何在元素的标题属性中添加 html 标签?

[英]How to add html tags in title attribute of an element?

I have a table and I want to add a title attribute to every td.我有一个表,我想为每个 td 添加一个 title 属性。

The title text contains html tags also like for example <p>testing <b>title</b></p>标题文本包含 html 标签,例如<p>testing <b>title</b></p>

When use this text as the value of the title attribute, and hover the mouse over the element, it also displays the html tags.当将此文本用作 title 属性的值,并将鼠标悬停在该元素上时,它还会显示 html 标签。

<td title="<p>testing <b>title</b></p>">abc</td>

Is there any way to use the correct formatting in the title attribute?有没有办法在 title 属性中使用正确的格式?

I am doing this in Drupal but if a php solution is present then I can use the php.我正在 Drupal 中执行此操作,但是如果存在 php 解决方案,那么我可以使用 php.ini 文件。

You can't use html tags in html attributes (which in your case is title ).您不能在 html 属性中使用 html 标签(在您的情况下是title )。

Instead you need to use JavaScript and HTML to create own custom tooltip which will be displayed like title attribute.相反,您需要使用 JavaScript 和 HTML 来创建自己的自定义工具提示,它将像标题属性一样显示。 For example you can use this library:例如你可以使用这个库:

https://popper.js.org/tooltip-examples.html https://popper.js.org/tooltip-examples.html

将 ( < ) 更改为 ( &lt; ) 并将 ( > ) 更改为 ( &gt; ):

title="&lt;p&gt;testing &lt;b&gt;title&lt;/b&gt;&lt;/p&gt;"**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM