简体   繁体   English

将“真棒字体”图标附加到<li>

[英]Append Font Awesome Icon to <li>

So, I would like to append an Font Awesome Icon to a new created li 因此,我想将Font Awesome Icon附加到新创建的li

On click I'm creating a new li , which needs two icons on it. 单击时,我正在创建一个新li ,它需要两个图标。

HTML: HTML:

<ul class="todo" id="todo">
</ul>

JS: JS:

function addItemToDo() {

    var list = document.getElementById('todo');

    var itemName = document.getElementById('item').value;
    var task = document.createElement('li');

    task.appendChild(document.createTextNode(itemName));
    list.appendChild(task);

    /* ADD ICONS */
    task.className += "fa fa-trash-o fa-3x";
    task.className += "fa fa-check-circle-o fa-3x";
}

The new element gets created, the icons are 'bugged' somehow. 创建新元素后,图标就以某种方式被“调试”。 I also tried to append them with the Unicode, which did not work for me either. 我还尝试用Unicode附加它们,这对我也不起作用。

Thanks for your help. 谢谢你的帮助。

You shouldn't add the font awesome classes to the li element, Instead you need to create something like this: 您不应该在li元素中添加超棒的字体类,而是需要创建如下代码:

<ul class="fa-ul">
  <li><i class="fa-li fa fa-check-square"></i>List icons</li>
  <li><i class="fa-li fa fa-check-square"></i>can be used</li>
  <li><i class="fa-li fa fa-spinner fa-spin"></i>as bullets</li>
  <li><i class="fa-li fa fa-square"></i>in lists</li>
</ul>

*from font awesome examples page *来自字体很棒的示例页面

create an ' i ' element and set ITS class to the font awesome glyph you want. 创建一个“ i ”元素,并将ITS类设置为所需的真棒字形。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM