我正在寻找打印出什么用户键入
<div style="text-align:center;">
<h3>- Students Name & Age -</h3>
<input id="d1">
<button class="button" onclick="addName()">Submit</button>
</div>
null
function addName() {
var div = document.createElement("div");
div.innerHTML = document.getElementById('d1').value;
document.getElementById("name").appendChild(div);
}
<div style="text-align:center;">
<h3>- Students Name & Age -</h3>
<input id="d1">
<button class="button" onclick="addName()">Submit</button>
</div>
<div id="name"></div>
您可以使用onkeyup
更新您按下的每个键的值
null
print = document.getElementById('print');
function printfun(){
print.innerHTML = document.getElementById('d1').value;
}
<div id="print"></div>
<div style="text-align:center;">
<h3>- Students Name & Age -</h3>
<input type="number" id="d1" onkeyup="printfun()">
<button class="button" id="SubmitStudentInformation" onclick="addName()">Submit</button>
</div>
使用JavaScript:
null
var addName = function() {
alert(document.getElementById('d1').value);
}
<div style="text-align:center;">
<h3>- Students Name & Age -</h3>
<input id="d1">
<button class="button" onclick="addName()">Submit</button>
</div>