javascript - 如何通过其arrtibute(不是ID不是Class)在html元素中添加css
问题描述
我需要通过属性“data-email”来显示以上跨度。
<span contenteditable="false" id="signature1596021675154" tabindex="1" data-role="test" data-email="qwerty" title="qwerty" data-name="name" style="z-index: 600; margin-right: 0px; visibility: visible;" class="index signature-container editor-elements valid_button"> </span>
解决方案
[attribute] 选择器用于选择具有指定属性的元素。
在你的CSS中你可以这样做:
span[data-mail] {
display: none;
}
或者
span[data-mail="qwerty"] {
display: none;
}
span[data-email]{
color: red
}
span[data-email="test"]{
color: blue
}
<span contenteditable="false" id="signature1596021675154" tabindex="1" data-role="test" data-email="qwerty" title="qwerty" data-name="name" style="z-index: 600; margin-right: 0px; visibility: visible;" class="index signature-container editor-elements valid_button">hello </span>
<span data-email="test">world</span>
推荐阅读
- python - 地块类别、比例、总数
- python - 我可以使用字典键的信息来定义同一个字典的另一个键吗?
- c# - 调用 CompleteAdding() 时如何处理 BlockingCollection<> 中的剩余数据
- plsql - 如何正确处理 PL SQL 中的触发器?
- postgresql - 如何在选择最大值时选择最大日期值
- php - 在 WooCommerce 商店页面中显示变体数量
- powershell - 空有效载荷。预期的 JSON 内容。Microsoft Graph 和 Powershell
- flutter - Flutter如何在appbar中扩展图像?
- r - 如何使用函数 fit() 预测单个值?
- linux - 在 ubuntu 20.04 上启动 GraphDB 9.5 的问题