Home  >  Article  >  Web Front-end  >  Sharing examples on how to switch between Chinese and English in HTML pages

Sharing examples on how to switch between Chinese and English in HTML pages

黄舟
黄舟Original
2017-07-22 10:20:153223browse

How to achieve bilingual switching of html pages? The crudest way is to create two pages, one in Chinese and one in English. A slightly milder method is: before each display, judge the current language flag and use if and else to solve it. In fact, although this method is not so crude, it is still disgusting enough. Let's use other methods. Stop talking nonsense and go straight to the code.

For the sake of simplicity, I use lang_flag as the switching flag, then the code is as follows;

test.html file:












test.js file:

var lang_flag = 1;
function fun()
{
	document.write(like[lang_flag]);
}

language.js file:

var love = ['Wo ai ni.', 'I love you!'];
var like = ['Wo xi huan ni.', 'I like you!'];

In this way, Chinese and English are in the resource file language.js, how great.

The above is the detailed content of Sharing examples on how to switch between Chinese and English in HTML pages. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn