【发布时间】:2023-01-05 23:36:26
【问题描述】:
当我使用数据属性时,它接受常规的 html 标签。但不接受儿童班。例如,看我的第一段代码;
<p>Lorem ipsum <a href="#" class="mi-tooltip" data-tooltip="<h1>MIUI_Tooltips is a lightweight.</h1><p>Around 5KB minified </p><u>and offering</u> a wide range <i>of configuration options.</i> <br><br><button> A Button </button>">condimentum</a>.Eros natoque.</p>
它运行良好,因为我在此处添加了常规的 html 标记。但是当我在 data-****** 属性中添加类和值时,它不起作用。看第二个代码;
<p>Lorem ipsum <a href="#" class="mi-tooltip" data-tooltip="<img src="https://images.pexels.com/photos/8726372/pexels-photo-8726372.jpeg?auto=compress&cs=tinysrgb&w=1260" width="100%" class="my-image"/><h1>MIUI_Tooltips is a lightweight.</h1><p>Around 5KB minified </p><u>and offering</u>">condimentum</a>.Eros natoque.</p>
如何在一个数据属性 HTML 标记中添加图像、类、链接和其他属性?
【问题讨论】:
-
你需要转义你的报价
-
@Pete 如果我转义引号,我如何使用/添加类、ID、URL ...?
标签: javascript html css attributes custom-data-attribute