js点击事件,数字累加

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js">
    </script>
    <title></title>
    <style>
        .id1{ 50px;height: 50px;background: red;}//id1的css样式
    </style>
</head>
<body>
    <div class="id1" id="num">9</div>
<script type="text/javascript">
    var i=9;                //创建一个名为i的对象
    btn = document.getElementById('num');
     btn.onclick=function (){//给id1新建一个点击事件

        i=i+1;               //每次点击i+1
     btn.innerHTML=i;
    }
</script>
</body>  
</html>

原文地址:https://www.cnblogs.com/xdong320/p/9373540.html