【发布时间】:2019-03-10 13:13:35
【问题描述】:
我想分别增加每个按钮的计数。我知道 .find jquery 函数会派上用场。但是我的按钮没有增加
即 “你点击了我:100 次” “你点击了我:22 次” “你点击了我:71 次”
$('#target').on('click', function() {
var numoftimes = parseInt($(this).find('span').html());
$(this).find('span').html(numoftimes + 1);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="target" type="button">You clicked me: <span>0</span>times</button>
<button id="target" type="button">You clicked me: <span>0</span>times</button>
<button id="target" type="button">You clicked me: <span>0</span>times</button>
【问题讨论】:
标签: javascript jquery scope