<!DOCTYPE html>
<html>
<head>
<title>NumberSum</title>
</head>
<script type="text/javascript">
window.onload=function()
{
var oText1=document.getElementById('txt1');
var oText2=document.getElementById('txt2');
var oBtn=document.getElementById('btn1');
oBtn.onclick=function()
{
var n1=parseInt(oText1.value);
var n2=parseInt(oText2.value);
if (isNaN(n1))
{
alert('text1 is not Number');
}
else if(isNaN(n2))
{
alert('text2 is not Number');
}
else
{
alert(n1+n2);
}
}
}
</script>
<body>
<input id="txt1" type="text" value="3">
<input id="txt2" type="text" value="4">
<input id="btn1" type="button" value="Sum">
</body>
</html>
网友评论