gpt4 book ai didi

javascript - 我想在不使用任何按钮的情况下显示两个数字的加法

转载 作者:行者123 更新时间:2023-11-28 04:45:07 26 4
gpt4 key购买 nike

<分区>

我有两个输入框,id分别是no1no2。我必须在两个输入上放置两个整数值并在不使用任何按钮的情况下显示它们的总和。我的代码有效,但它只显示单个值,而不显示计算总和。

如何在用户打字时实时显示我的附加值?

var c;
var a = document.getElementById("no1");
var b = document.getElementById("no2");
var number = document.getElementById("number");
var m = document.getElementById("message");

a.onfocus = function() {
m.style.display = "block";
}

a.onblur = function() {
m.style.display = "none";
}

a.onkeyup = function() {
var c;
if (isNaN(a.value) == false) {
c = a.value + b.value;
m.innerHTML = c;
} else {

m.innerHTML = "<font color='red' size='45px'><strong>Must containe number only</strong></font>";
}
}
b.onfocus = function() {
m.style.display = "block";
}
b.onblur = function() {
m.style.display = "none";
}
b.onkeyup = function() {

if (isNaN(b.value) == false) {
c = a.value + b.value;
m.innerHTML = c;
} else {

m.innerHTML = "<font color='red' size='45px'><strong>Must containe number only</strong></font>";
}
}
<div class="container">
<input type="text" id="no1" name="no1" />
<input type="text" id="no2" name="no2" />
<button onclick="myFun()">Press Me</button>
</div>

<center>
<font color="blue" size="45px" id="message"></font>
</center>

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