JS中的加法计算器

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function Add() {
            var txt1 = document.getElementById('Number1');
            var txt2 = document.getElementById('Number2');
            var txtResult = document.getElementById('Result');
            if (txt1 && txt2 && txtResult) {
                txtResult.value =parseInt(txt1.value,10) +parseInt(txt2.value,10);
            }
        }
    </script>
</head>
<body>
<input type="text" id="Number1" />+
<input type="text" id="Number2" />
<input type="button" value="=" onclick="Add()" />
<input type="text" id="Result" readonly="readonly" />
</body>
</html>

posted @ 2012-11-24 19:54  FiberHomer  阅读(239)  评论(0编辑  收藏  举报