直接上例子
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<button id="bt1">11111</button>
</body>
<script src="https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js"></script>
<script>
//方法1:使用
var RX = {};
RX.number = 1;
$('#bt1').on(
'click',
function(){
console.log("您点击了第"+RX.number+"次");
RX.number++;
}
);
//冻结在函数里面
(function(obj){
var i = 1;
$('#bt1').on(
'click',
function(){
console.log("您点击了第"+i+"次");
i++;
}
);
})(window);
</script>
</html>