In ASP. JavaScript in the Chinese and English (multi-language) Implementation of the program is a simple introduction of JS to implement a multi-language scheme. Here's another way to tell, though very similar, but there are some areas that need to be carefully pondered, not to mention, first look.
The code in lang.html is as follows: Because jquery is used in this article, the JS file of jquery is loaded first. Separately loading the required two custom JS
<! DOCTYPE html>
"http://www.w3.org/1999/xhtml " lang="en " >
"Content-type"Content="Text/html;charset=utf-8"> <title></title> <script src="/common/jquery-1.8.2.min.js"Type="Text/javascript"> </script> <script src="/common/common.js"></script> <script src="/common/commonglobalvariables.js"></script>"Javascript:seten ()">En</a> <a href="Javascript:setzh ()">Cn</a> <a href="Javascript:commonalert ()">common</a> <a href="Javascript:globalalert ()">Global</a></body>
In this paper, JS Multi-language implemented in two formats.
The first type:
First look at Common.js.
//Dynamic Loading JSfunction Loadjavascriptinhead (file) {varHead = $ ('Head'); $("<script></script>"). attr ({src:file, type:'Text/javascript'Id:'Loadscript'}). AppendTo (head);}//Comm Init languagefunction Initpubliclanguageculture () {if(Document.cookie.indexOf ("en") >0) {Loadjavascriptinhead ('/common/en-us.js'); Loadjavascriptinhead ('/common/englobalvariables.js'); } Else{Loadjavascriptinhead ("/common/zh-cn.js"); Loadjavascriptinhead ('/common/cnglobalvariables.js'); }}function Commonalert () {initpubliclanguageculture (); alert ($.common.lang.user);} function Seten () {Document.cookie="lg=en";} function Setzh () {Document.cookie="LG=CN";}
The Common.js defines the Seten () Setzh () Commonalert () three methods that correspond to hyperlinks in the HTML file.
Loadjavascriptinhead () is a dynamic loading JS method, specifically described in jquery dynamic loading JS three ways.
In the initialization language is the dynamic loading of the two languages by selecting the JS correspondence as follows:
En-us.js Code:
(function ($) { if (typeof'undefined') { = {}; } = { "UserName", "Password " }}" (JQuery);
Zh-cn.js Code:
(function ($) { if (typeof'undefined') { = {}; } = { " username ", Pwd:" password " }}) (JQuery);
The second type:
The Commonglobalvariables.js code is as follows:
var tipmsg = { " error ", successmsg:" correct "= tipmsg;function Globalalert () { initpubliclanguageculture (); alert (tipmsg.errmsg);}
This inside is set the global variable $. Tipmsg. You can then switch between English and Chinese by modifying the value of the global variable.
Load the Chinese and English JS code as follows:
Cnglobalvariables.js Code:
" Error global variable " " correct global variables ";
Englobalvariables.js Code:
" Error " "right";
Asp. NET JavaScript in Chinese and English (multi-language) implementation scheme (II.)