日期:2014-05-16 浏览次数:20438 次
<script>
var en = location.search.indexOf('lan=en') != -1, zh = location.search.indexOf('lan=zh') != -1;
window.onload = function () {
var as = document.getElementsByTagName('a');
for (var i = 0; i < as.length; i++)
if (as[i].href.indexOf('lan=') == -1)//链接包含过语言选项就不增加语言选项
as[i].href = (as[i].href.indexOf('?') == -1 ? '?' : '&') + 'lan=' + (en ? 'en' : zh ? 'zh' : '');
if (zh) document.getElementById('dvZH').style.display = 'none';
else if (en) document.getElementById('dvEN').style.display = 'none';
}
document.write('<h1>' + location.pathname + '</h1>');
if (en) document.write('language is english');
else if (zh) document.write('语言为中文');
else document.write('没有指定语言选择!!no language!');
</script>
<h1>下面这些链接保持和当前语言一直</h1>
<a href="1.html">1.html</a><br /><a href="2.html">2.html</a><br /><a href="data.html">data.html</a>
<div id="dvZH">
<h1>切换为中文</h1>
<a href="1.html?lan=zh">1.html</a><br /><a href="2.html?lan=zh">2.html</a><br /><a href="data.html?lan=zh">data.html</a></div>
<div id="dvEN">
<h1>切换为英文</h1>
<a href="1.html?lan=en">1.html</a><br /><a href="2.html?lan=en">2.html</a><br /><a href="data.html?lan=en">data.html</a></div>