以下是index.html
文件:
<html>
<head>
<script>
function ChangePageLanguage()
{
var e = document.getElementById("langDD");
var lang = e.options[e.selectedIndex].value;
if (lang == "it")
{
var scrptE = document.createElement("script");
scrptE.setAttribute("type", "text/javascript");
scrptE.setAttribute("language", "JavaScript");
scrptE.setAttribute("src", "language_it.js?" + (Date.now() % 10000));
var head = document.getElementsByTagName("head")[0];
head.appendChild(scrptE);
document.getElementById('p1').innerHTML = obj[key1];
//document.getElementById('p2').innerHTML = obj[key2];
}
}
</script>
</head>
<body>
<select onchange="ChangePageLanguage()" id="langDD">
<option value="en">English</option>
<option value="it">Italian</option>
</select>
<br/>
<span id="p1">
</span>
<br/>
<span id="p2">
</span>
</body>
</html>
我有以下内容language_it.js
:
var obj = {
key1: Il mio nome è Azeem,
key2: Sono uno sviluppatore di Software
};
当我从下拉菜单中选择意大利语时,它应该key1
在 id="p1" 的 span 对象中打印值,但它不是...中的键/值对有什么问题language_it.js
吗?请帮帮我。