<head runat="server">
    <title>JavaScript实现加法计算器</title>
    <script type="text/javascript">       
        function Sum()
        {
            var txtbox1 = document.getElementById("txtbox1");
            var txtbox2 = document.getElementById("txtbox2");
            var sum = document.getElementById("sum");
            sum.value = parseInt(txtbox1.value) + parseInt(txtbox2.value);
        }
    </script>
</head>
<body>
    <input type="text" id="txtbox1" />+
    <input type="text" id="txtbox2" />
    <input type="button" value="=" onclick="Sum()" />
    <input type="text" id="sum" />
</body> 
//参考上面,如果是变量和数字相加的话,一般的txtbox1.value+1,只是简单的连接在了一起并不是真正意义上的相加,
//所以此处需将字符创转换为内部对象Number,来实现真正意义上的相加
var s=2;
var sum=Number(txtbox1.value)+s;
alert(sum);