Asp. NET JavaScript in Chinese and English (multi-language) implementation scheme (II.)

Source: Internet
Author: User

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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.