修复了我的代码。但是,现在弹出警报说您的值是 NaN。然而,它是一个数字。parseInt 有点帮助。我很可能错过了一些东西。现在我的代码如下所示:
<input id="a" type="text">
<script>
function myFunction()
{
x=document.getElementById("a").value;
if(x==""||isNaN(x))
{
alert("Your First Number is Not Numeric");
}
a=document.getElementById("a").value;
}
</script>
<button type="button" onclick="myFunction()">Submit Number</button>
<br />
<p>Second Number</p>
<br />
<input id="b" type="text">
<script>
function myFunction1()
{
x=document.getElementById("b").value;
if(x==""||isNaN(x))
{
alert("Your Second Number is Not Numeric");
}
b=document.getElementById("b").value;
}
</script>
<button type="button" onclick="myFunction1()">Submit Number</button>
<br />
<script>
function add()
{
d=parseInt(a);
e=parseInt("b");
c=d+e;
alert("The number is " + c);
}
</script>
<button type="button" onclick="add()">Add numbers</button>