我需要创建一个显示 10 个按钮 (0-9) 的网页。例如,当单击 4 号按钮时,网页应在按钮下方显示以下消息:
You have entered four
例如,当接下来点击 9 号按钮时,消息将变为:
You have entered four-nine
这个过程继续。
这是我到目前为止所拥有的。我已经能够单独显示每个数字,但无法弄清楚如何在单击数字后继续将数字添加到显示中。
function number0(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "zero";
}
function number1(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "one";
}
function number2(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "two";
}
function number3(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "three";
}
function number4(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "four";
}
function number5(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "five";
}
function number6(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "six";
}
function number7(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "seven";
}
function number8(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "eight";
}
function number9(){
var displaySpan = document.getElementById("display");
displaySpan.innerHTML = "nine";
}
<button onclick="number0()">0</button>
<button onclick="number1()">1</button>
<button onclick="number2()">2</button>
<button onclick="number3()">3</button>
<button onclick="number4()">4</button>
<button onclick="number5()">5</button>
<button onclick="number6()">6</button>
<button onclick="number7()">7</button>
<button onclick="number8()">8</button>
<button onclick="number9()">9</button>
<br /><br />
<span id="display"></span>
大话西游666
米琪卡哇伊
翻过高山走不出你
墨色风雨
相关分类