NumberSum

作者: Jadon7 | 来源:发表于2018-10-07 15:42 被阅读0次
<!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>

相关文章

网友评论

      本文标题:NumberSum

      本文链接:https://www.haomeiwen.com/subject/eymlaftx.html