我尝试了在这里找到的其他解决方案,但是没有任何效果。我需要将fontawesome f14a设置为一个字段
怎么了 ?

document.getElementById('property_charges').setAttribute('class', 'fontawesome-placeholder');
document.getElementById('property_charges').placeholder = '&#f14a';


和CSS:

.fontawesome-placeholder {
  //padding:10px;
  //font-family: FontAwesome;
  //z-index: 9999;
  //z-index: 1;
  font: normal normal normal 14px/1 FontAwesome;
  font-size: inherit;
  text-rendering: auto;
}


关于“重复”的建议解决方案不起作用+我不想在项目中使用Jquery

最佳答案

使用JS / jQ和unicode时,必须在正斜杠后添加u。除非打算将其直接放入HTML,否则请勿使用HTML实体。还有一些必需的CSS样式。



document.getElementById('fa').setAttribute('placeholder', '\uf14a');

.icon {
  display: inline-block;
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  -webkit-font-smoothing: antialiased;
}

<link href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" rel="stylesheet" crossorigin="anonymous">

<input id='fa' class='icon'>

07-24 19:51
查看更多