我刚刚开始使用 html,想要创建两个输入字段,用户可以在其中输入某种类型的文本,当他单击提交按钮时,会出现一个小弹出窗口,显示他刚刚输入该字段的信息。
我知道这就像在面包上涂黄油一样简单,但我无法理解它-
<script type="text/javascript">
function showInfo()
{
var Größe=Number(document.getElementById("Größe").value);
var Gewicht=Number(document.getElementById("Gewicht").value);
return window.alert("Sie haben als Körpergröße document.getElementById("Größe") und als Gewicht document.getElementById("Gewicht")
}
<p>Körpergröße:
<input type="text" id="Größe"/>
</p>
<p>Körpergewicht:
<input type="text" id="Gewicht"/>
</p>
<input type="submit" value="showInfo" onclick="showInfo()">
最佳答案
尝试以此作为开始并对其进行扩展。
function showResult() {
var el = document.getElementById('userInput');
var val = el.value;
if (!val) {
window.alert("No value was entered");
} else {
window.alert(val);
}
}
<input type="text" id="userInput">
<button type="button" onclick="showResult()">Show Result</button>
关于javascript - 如何读出并显示用户在输入字段中键入的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54037603/