gpt4 book ai didi

javascript - 使用 html 和 javascript 添加两个数字

转载 作者:行者123 更新时间:2023-11-30 16:00:34 25 4
gpt4 key购买 nike

<分区>

我正在尝试将两个数字相加。从用户那里获取输入,但我无法找到我出错的地方。每次我点击提交时,它只会刷新页面。

<!--Html -->



<html>
<body>
<div class="container-fluid">
<header>
<h1>Business Registration Address Setup</h1>
</header>

<form>
<label>number 1</label>
<input type="text" name="number1" id="number1" placeholder="enter single digit number"> <br>
+<br>
<label>number 2</label>
<input type="text" name="number2" id="number2" placeholder="enter single digit number"><br>
<button type="submit" class="btn btn-info" onclick="submit1()">submit</button><br><br>
<div class="screen" id="screen1"></div>

</form>

</div> <!-- End Container-->



<footer>

</footer>
<script type="text/javascript">
function submit1(){
var a = document.getElementByID("number1").value;
var b = document.getElementByID("number2").value;
var c = a + b;
document.getElementByID("screen1").innerHTML=c;
}
</script>

</body>
</html>

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com