引导程序获取字形代码

Bootstrap get glyphicon code

本文关键字:代码 字形 获取 引导程序      更新时间:2023-09-26

我的任务是从引导程序glyphicon元素中获取代码(例如"''e020")。

我尝试了以下方法:

html:

<div id="glyph" class="glyphicon glyphicon-trash"></div>

js:

$( document ).ready(function() {
    console.log(window.getComputedStyle($('#glyph')[0], ':before').content);
});

但在这里,我只能实现字符本身,而不能实现原始代码。

有没有办法得到字符串"''e020"?

您可以使用带有16参数的toString方法将char转换为HEX:

var content = window.getComputedStyle($('#glyph')[0], ':before').content
var result = '''' + content.charCodeAt(1).toString(16);    
alert(result);

参见的工作示例