HTML代码
<input type="button" name="" value="go" onclick="a()">
<br>
请输入字母:<input type="text" id="txt" value="">
<div id="z"></div>
JS 代码块
function a() {
var txt = document.getElementById("txt");
var str = "";
for (var i = 0; i < txt.value.length; i++) { //小写字符ascll码为
if (txt.value[i].charCodeAt() <= 122 && txt.value[i].charCodeAt() >= 97) {
str += txt.value[i].toUpperCase();
} else {
str += txt.value[i].toLowerCase();
}
}
document.getElementById("z").innerHTML=str;
}