Home > Web Front-end > HTML Tutorial > 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

黄舟
Release: 2017-07-22 10:20:15
Original
3403 people have browsed it

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:

<html>
<head>
<script type="text/javascript" src="language.js"></script>
<script type="text/javascript" src="test.js"></script>

<script>
var lang_flag = 1;
</script>
</head>

<body>
<script> 
document.write(love[lang_flag]);
fun();
</script>
</body>
</html>
Copy after login

test.js file:

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

language.js file:

var love = [&#39;Wo ai ni.&#39;, &#39;I love you!&#39;];
var like = [&#39;Wo xi huan ni.&#39;, &#39;I like you!&#39;];
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template