admin管理员组文章数量:1334674
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 I change the chinese characters to "Name", it starts working again just fine. Is there something special I have to do here?
In the header, I do see this as the encoding...
<meta http-equiv="content-type" content="text/html; charset=utf-8">
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 I change the chinese characters to "Name", it starts working again just fine. Is there something special I have to do here?
In the header, I do see this as the encoding...
<meta http-equiv="content-type" content="text/html; charset=utf-8">
Share
Improve this question
asked Nov 7, 2013 at 3:11
Dean HillerDean Hiller
20.2k31 gold badges146 silver badges228 bronze badges
3
- Works for me - jsfiddle/k7X2T – Phil Commented Nov 7, 2013 at 3:18
- 6 are you saving your js file using utf-8 too? – aaronps Commented Nov 7, 2013 at 3:21
- I was using instapage. so they save the files and chinese worked when I typed it in but not in their add custom html for some reason....support did something in the header that seems to be working though for me now(so I just use javascript ot inject into the html some chinese since I can't write the chinese in html(It was sort of weird and I am not sure why it didn't work when the rest of hte chinese worked). – Dean Hiller Commented Nov 7, 2013 at 18:23
1 Answer
Reset to default 5If 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
本文标签: how to inject chinese characters using javascriptStack Overflow
版权声明:本文标题:how to inject chinese characters using javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351375a2458563.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论