有人在How to getting browser current locale preference using javascript?
中向我引用了此片段 var l_lang;
if (navigator.userLanguage) // Explorer
l_lang = navigator.userLanguage;
else if (navigator.language) // FF
l_lang = navigator.language;
else
l_lang = "en";
我想知道如何添加它来为每种语言做点什么。如果声明那么,如何使用此语言返回语言并为每个语言执行某些操作?这就是我的想法。
var l_lang;
if (navigator.userLanguage) // Explorer
l_lang = navigator.userLanguage;
else if (navigator.language) // FF
l_lang = navigator.language;
else
l_lang = "en";
'do something
l_lang = "fr";
'do something
l_lang = "ru";
'do something
l_lang = "de";
'do something
答案 0 :(得分:0)
尝试使用javascript切换语句(documentation)
switch(l_lang)
{
case 'en':
//execute code block 1
break;
case 'fr':
//execute code block 2
break;
default:
//code to be executed if n is different from case 1 and 2
}