JQuery实现两数相加

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <script src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#btn1').click(function () {
                var num1 = $('#txt1').val();
                var num2 = $('#txt2').val();
                var num3=parseInt(num1) + parseInt(num2);
                $('#txt3').val(num3);
                });
        });
    </script>
</head>
<body>
    <input id="txt1" />+<input id="txt2" /><input type="button" value="=" id="btn1" /><input id="txt3" />
</body>
</html>

评论