<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="language.js"></script>
<title></title>
</head>
<body>
<button id="a1">中文</button>
<a id="a2">香蕉</a>
<a id="a3">苹果</a>
<button id="a4">英文</button>
<script>
$("#a1").click(function() {
cl(this);
});
</script>
<script>
$("#a4").click(function() {
for(var i = 2; i <= 3; i++) {
var s = document.getElementById("a" + i).innerHTML;
document.getElementById("a" + i).innerHTML = getjson(s);
//
}
});
</script>
</body>
</html>
function getjson(key) {
var result = "";
$.ajax({
type: "get",
url: "a2.json",
contentType: "application/json; charset=utf-8",
dataText: "jsonText",
async: false,
cache: false,
dataType: "json",
success: function(result) {
// alert(result);
for(var item in result) {
if(item == key) { //item 表示Json串中的属性,如'name'
var jValue = result[item]; //key所对应的value
return jValue;
}
}
}
});
}