js累加按钮

<!DOCTYPE HTML>
<html>
    <head>
        <title>累加按钮</title>
        <mate charset="utf-8" />
        <style type="text/css">
        *{ padding: 0px; margin: 0px; text-align: center; }
        .app3{ margin: 30px auto; }
        .app3 input{ width: 40px; height: 34px; font-size: 20px; cursor: pointer; }
        </style>
    </head>
    <body>
        <div class="app3">
            <input type="button" value="0" />
        </div>

        <script type="text/javascript">
            window.onload = function(){
                var addbtn = document.getElementsByTagName("input")[0];
                var number = 0;
                addbtn.onclick = function(){
                    number++;
                    this.value = number;
                    alert(number);
                }
            }
        </script>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_44254672/article/details/91396018
今日推荐