显示html& copy;的文本值输入type = text中的实体? [英] show text value of html © entity in input type=text?
问题描述
我正在从包含版权字符的json文件中加载值.它作为html实体存储在json中-©
呈现©.
I'm loading a value from a json file which contains a copyright character. It's stored in the json as a html entity - ©
which renders ©.
Handlebars正在为我渲染文件编辑器,这种方式是:如果字符串较长,则将其变成文本区域;如果字符串较短,则将其变为文本输入框.当呈现为<textarea>
时,该值将显示为其字符串版本-类似于© 2013 blah foo inc
,而如果将该值写入<input type='text'>
值,则浏览器会将其呈现为其等效的实体,而不显示字符串本身.我不知道如何显示实体本身的文本值,而不是其解释的形状.
Handlebars is rendering a file editor for me in such a way that if the string is long it gets made into a textarea, and if it's short then it becomes a text input box instead. When rendered to a <textarea>
the value is shown as its string version - something like © 2013 blah foo inc
, whereas if the value is written to a <input type='text'>
value, then the browser renders it as its entity equivalent, no the string itself. I can't figure out how to make the text value of the entity itself appear, not its interpreted shape.
推荐答案
据我了解,您想将html实体名称(©
)转换为输入类型text
/textarea
的字符(©).
As I understand that you want to convert html entity name (©
) into it's character (©) in input type text
/textarea
.
var content = "© 2014 blah foo inc";
var copyright = $('<div>').html('©').text();
var encoded = content.replace(/©/g, copyright);
alert(encoded); // or $('#input_id').val(encoded);
这篇关于显示html& copy;的文本值输入type = text中的实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!