任何人都可以帮我解决这个问题吗?我在javascript中创建了一个自动增量字母,但如果单击按钮则没有任何反应。
function myFunction() {
var test = 5;
var b = String.fromCharCode(64 + parseInt(test.toString()));
var a = String.fromCharCode(64 + 1);
for (var i = a; i <= b.length; i++) {
document.getElementById("demo").innerHTML = text[i];
};
}
&#13;
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
&#13;
答案 0 :(得分:0)
对于初学者,您的代码中未定义text
。
var currentCode = 0;
function nextChar() {
currentCode++;
var character = String.fromCharCode(64 + currentCode);
document.getElementById("demo").innerHTML = character;
}
nextChar(); // Initialize with "A"
&#13;
<button onclick="nextChar()">Try it</button>
<p id="demo"></p>
&#13;
答案 1 :(得分:0)
这是我对你的尝试
function myFunction() {
for (i = 65; i < 91; i++) {
var letter = String.fromCharCode(i);
document.write(letter);
}
}
&#13;
<button onclick="myFunction()">Try it</button>
&#13;