Today, there is a very interesting thing, because I need to use JS to achieve multi-language, I am in the JS file defined a different variable, try to use a variable concatenation string to make a defined variable name, the result stitching, the display is a string, not a variable, so cannot parse
zh_test = ' Hello '; tw_test = ' Hello '; En_test = ' Hello '; Then JS try to use the previous language shorthand as a variable, splicing the string behind the var lang = ' zh '; var language = lang + ' _test '; <pre name= "Code" class= "JavaScript" >alert (language); The result ' lang_test ' <pre name= "code" class= "JavaScript" >//then the result of the alert is lang_test, but this is obviously not what I want, What I want is to read the Chinese Simplified ' hello ' after stitching , and I want it to be identified as a variable instead of a string, and finally with an eval () function to solve it; var language = eval (lang + ' _test '); alert (language); The result ' Hello ' is not a big article, just some small knowledge points encountered, share sharing
How to make the JS variable and string concatenation, is a variable instead of a string