以下是 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
};
When I select Italian Language from Dropdown, it should print key1
value in span object with id="p1", but its not... Is there anything wrong with key/value pairs in language_it.js
?
Please help me out.