【问题标题】:° not showing in placeholder when added with .placeholder° 与 .placeholder 添加时不显示在占位符中
【发布时间】:2017-08-10 17:40:33
【问题描述】:

我正在尝试使用 .placeholder 更改输入中的占位符文本。我正在使用

°

得到一个°

cel.onclick = function() {
    cel.className += "active";
    reset();
    faren.classList.remove("active");
    inp.placeholder = "Enter °C";
};

faren.onclick = function() {
    faren.className += "active";
    reset();
    cel.classList.remove("active");
    inp.placeholder = "Enter °F";
};

这输出° 而不是符号,任何人都可以解释如何更改它。谢谢。

【问题讨论】:

  • 有什么阻止您将实际的°符号粘贴到占位符字符串中吗?
  • 你的意思是它输出 °?
  • 是的,抱歉忘记添加代码
  • inp.placeholder = 'Enter '+String.fromCharCode(176)+ 'C';
  • 实际上没有@Zac 我觉得有点愚蠢,因为我不得不谷歌如何放置°符号。谢谢!

标签: javascript input placeholder


【解决方案1】:

尝试对符号使用 javascript 字符转义码(如 \u00B0)而不是 HTML 实体代码(如 °):

inp.placeholder = "Enter \u00B0C";

您可以使用this web tool 来查找给定 HTML 实体的 javascript 字符转义。

【讨论】:

    猜你喜欢
    • 2015-04-10
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    • 2015-01-23
    • 2018-10-30
    • 2013-06-27
    • 2021-08-07
    相关资源
    最近更新 更多