<ul>
<li><a href="javascript:;" class="ml-praise">数量:<span class="ding-num">100</span></a></li>
<li><a href="javascript:;" class="ml-praise">数量:<span class="ding-num">200</span></a></li>
<li><a href="javascript:;" class="ml-praise">数量:<span class="ding-num">300</span></a></li>
<li><a href="javascript:;" class="ml-praise">数量:<span class="ding-num">400</span></a></li>
</ul>
JS实现代码:
function addPraiseNum() {
var praiseObjs = document.getElementsByClassName('ml-praise');
for (var i = 0; i < praiseObjs.length; i++) {
var praiseObj = praiseObjs[i];
praiseObj.onclick = (function (dingObj) {
return function () {
dingObj.innerHTML = parseInt(dingObj.innerHTML) + 1;
};
})(praiseObj.getElementsByClassName('ding-num')[0]);
}
}
实现效果如下: