1

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">
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
  • Works for me - http://jsfiddle.net/k7X2T/ – Phil Nov 07 '13 at 03:18
  • 6
    are you saving your js file using utf-8 too? – aaronps Nov 07 '13 at 03:21
  • I was using instapage.com 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 Nov 07 '13 at 18:23

1 Answers1

5

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
Community
  • 1
  • 1
Fabio Beltramini
  • 2,441
  • 1
  • 16
  • 25