问题
I have a String like the following. Please take a look:
I put it as a image, this is not displaying in here too. If I put that String here it becomes the following:
21154537878887GHE\u0044\u0045
Now my question: is there any way to put the original String into an HTML <textarea> without changing the encoding?
回答1:
I think you must define your char set in the head.
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<meta name="generator" content="TextMate http://macromates.com/">
<meta name="author" content="denis kohl">
<!-- Date: 2014-09-04 -->
</head>
<body>
回答2:
Try adding the attribute accept-charset="UTF-8" to the HTML form element that contains the textarea. Then parse the encoded value via JavaScript. For example:
HTML:
<form accept-charset="UTF-8">
<textarea id="textBox"></textarea>
</form>
JavaScript:
document.getElementById("textBox").value = "21154537878887GHE\u0044\u0045";
回答3:
<textarea name="Input" cols="36" rows="5" wrap="virtual">
Could you try to define the wrap method, you can choose:
wrap: off, virtual, hard, physical, soft
The Textarea formatting looks nothing like they originally intended. Typically, all the Textarea text will squashed into a single paragraph with none of the original line breaks or spacing in evidence.
The reason for this is that the CGI program (to handle the text in the textbox) has to specify a MIME Type when they are preparing the email or other document and many of these programs elect to use a MIME Type of "text/html" so that they can use HTML formatting to make the email or document more presentable. The problem with this approach is that the contents of an HTML Textarea input box require the use of a MIME Type "text/plain" otherwise the Textarea formatting will not display properly in the final output.
<meta http-equiv="Content-Type" content="text/plain; charset=utf-8">
Knowing the above I hope this will help you to find the solution.
回答4:
Do this:
<textarea>211c;545c;378887GHE\u0044\u0045</textarea>
Note that what happens when this is rendered is that all the characters that can be displayed in the chosen (in css) font are displayed normally, while most browsers fall back to the Unicode BMP Fallback Font (http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&item_id=UnicodeBMPFallbackFont) which simply fills in the gaps in whatever font you might be using. The exact result will be browser-dependent.
来源:https://stackoverflow.com/questions/25665073/how-can-i-show-following-text-in-html-textarea