How To Inject Chinese Characters Using Javascript?
I have this code but it only works using english characters $( 'input[name*='Name']' ).attr('placeholder','姓名'); My web page displays other chinese characters just fine and if
Solution 1:
If the script is inline (in the HTML file), then it's using the encoding of the HTML file and you won't have an issue.
If the script is loaded from another file:
- Your text editor must save the file in an appropriate encoding such as utf-8 (it's probably doing this already if you're able to save it, close it, and reopen it with the characters still displaying correctly)
- Your web server must serve the file with the right http header specifying that it's utf-8 (or whatever the enocding happens to be, as determined by your text editor settings). Here's an example for how to do this with php: Set HTTP header to UTF-8 using PHP
- If you can't have your webserver do this, try to set the charset attribute on your script tag (e.g.
<script type="text/javascript" charset="utf-8" src="..."></script>
> I tried to see what the spec said should happen in the case of mismatching charsets defined by the tag and the http headers, but couldn't find anything concrete, so just test and see if it helps. - If that doesn't work, place your script inline
Post a Comment for "How To Inject Chinese Characters Using Javascript?"