javascript - 将 fontawesome 图标设置为占位符

标签 javascript font-awesome

我尝试了这里找到的不同解决方案,但没有任何效果。我需要的是将 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'>

关于javascript - 将 fontawesome 图标设置为占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55747077/

相关文章:

css - 我如何使用 Font Awesome 作为笔触

php - 在选择选项中使用 Font Awesome

javascript 原型(prototype)与 this

javascript - 我需要使用 JavaScript 可视化动态集合,可以使用响应式扩展来实现吗?

javascript - React Native Controller FormData TextInput 不重置

xamarin - 无法让 FontAwesome 5 与 Xamarin Forms、iOS 和 Android 配合使用

html - Font Awesome Icons,如何添加悬停效果?

html - Bootstrap 4 中 Font Awesome 上的圆形转到顶部按钮

javascript - 如何在 $.post() 回调显示 alert() 之前调用函数?

javascript - html 使用 javascript 为输入文本赋值不起作用