简体   繁体   中英

JavaScript Unicode Input Text Box

I'm trying to use JavaScript to set the value of an Input Text Box to this Emoji >> 🤔
But it didn't work as I expect it to.
I've tried several different format to express the Unicode but none of it works.
I've included the snippet that I've tried.

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <script> var myTextBox = document.createElement("input"); document.body.appendChild( myTextBox ); myTextBox.value = "&#129300"; // None of below will work: // \ᾑ4 // \\xF0\\x9F\\xA4\\x94 // &#129300; </script> <p> &#129300; </p> </body> </html> 

Any idea on how to do this properly?

You need to convert it into a surrogate pair: "\?\?"

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <script> var myTextBox = document.createElement("input"); document.body.appendChild( myTextBox ); myTextBox.value = "\?\?"; </script> <p> &#129300; </p> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM