【问题标题】:Bootstrap get glyphicon codeBootstrap 获取 glyphicon 代码
【发布时间】:2016-04-20 20:33:50
【问题描述】:

我的任务是从引导 glyphicon 元素(例如“\e020”)获取代码。

我尝试了以下方法:

html:

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

js:

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

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

有没有办法得到"\e020"这个字符串?

【问题讨论】:

    标签: javascript twitter-bootstrap twitter-bootstrap-3 glyphicons


    【解决方案1】:

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

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

    working example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 2014-10-21
      • 2015-10-02
      相关资源
      最近更新 更多