°添加.placeholder时不显示占位符

时间:2017-03-19 12:46:19

标签: javascript input placeholder

我正在尝试使用.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";
};

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

1 个答案:

答案 0 :(得分:1)

尝试使用javascript字符转义码(如\u00B0)代替HTML实体代码(如°):

inp.placeholder = "Enter \u00B0C";

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