jquery - 之前的jquery伪元素,内部带有反斜杠的内容来自attr(data-before)
问题描述
我有一个小问题。我想使用 jQuery 更改字形图标(图标字体),如下所示:
var icoList = 'E251'
var icon = $('ul > li:has(ul)', $this);
icon.addClass('icon');
icon.attr('data-before', '&#x' + icoList); // this doesn' work, -> 
icon.attr('data-before', '\' + icoList); // this doesn' work, -> TypeError
icon.attr('data-before', '\\' + icoList); // this doesn' work, -> \E251
icon.attr('data-before', '"\\' + icoList + '"'); // this doesn' work, -> "\E251"
我只得到一个字符串。
我的CSS是这样的:
ul li::before {
font-family: "Glyphicons Halflings";
content: attr(data-before);
}
在我的 HTML 中,我尝试了这个:
<nav id="Nav-Main" class="nav-main">
<ul>
<li data-before=""> <!-- this works fine -->
<a href="#">Home</a>
<ul class="flexy">
<li>
<a href="#">Referenzen</a>
</li>
<li>
<a href="#">Downloads</a>
</li>
</ul>
</li>
</ul>
</nav>
如果我在我的 html 代码中使用数据,那么它工作正常。
我做错了什么?如何使用代码获取此图标?
解决方案
推荐阅读
- javascript - React - 使用 axios 更新列表并同时刷新
- r - 如何在 dplyr::semi_join() 中针对 Oracle 指定覆盖 = T
- python-3.x - 在读取 csv 时识别 pandas 中的日期列
- python - Google Datastore:迭代器已经启动 - 如何使用这些迭代器?
- c# - C# 中的 Windows 时区下拉菜单
- python - 无限滚动条不适用于 django
- javascript - 简单上传ckeditor 5 无法上传文件:未定义
- javascript - 获取 HTTP 状态 500 ?将 tomcat 7 升级到 8 时出现内部服务器错误
- asp.net-mvc - 在生产中找不到视图,在本地工作正常
- c# - 使用 Azure Log Analytics 在 Azure Function v3 中进行结构化日志记录