欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

中英文切换

程序员文章站 2024-01-26 23:08:34
//首页var zh_index = { "index1":"首页", "index2":"产品实例" };var en_index = { "index1":"index", "index2":"Product examples" }; //服务支持var zh_serviceSupport = ......

//首页
var zh_index = {
"index1":"首页",
"index2":"产品实例"
};
var en_index = {
"index1":"index",
"index2":"product examples"
};

//服务支持
var zh_servicesupport = {
"servicesupport1":"首页",
"servicesupport2":"产品实例"
};
var en_servicesupport = {
"servicesupport1":"index",
"servicesupport2":"product examples"
};




var zh = {"index":zh_index,"servicesupport":zh_servicesupport};
var en = {"index":en_index,"servicesupport":en_servicesupport};

var language = [zh,en];


$(function(){
var value = sessionstorage.getitem("language");
var pathname = window.location.pathname;
var index = pathname.lastindexof("\/");
pathname = pathname.substring(index + 1, pathname.length).split(".html")[0];
if(value==null || value==0){
value=0;
}
var data = language[value][pathname];
for (var i = 1; i <= 2; i++) {
$("#"+pathname+i).text(data[pathname+i])
}
});
$("#change").click(function() {
var value = sessionstorage.getitem("language");
if(value==="1"){
sessionstorage.setitem("language", "0");
}else{
sessionstorage.setitem("language", "1");
}
window.location.reload();
})