Bootstrap 获取字形代码
Bootstrap get glyphicon code
我的任务是从 bootstrap 字形元素(例如“\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);
我的任务是从 bootstrap 字形元素(例如“\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);