for(var i = 0; i < tr.length; i++) { tr[i].onclick=function(e){ e = e || window.event; var el = e.srcElement; var cls = el.className; var input = this.getElementsByTagName('input')[1]; var raduce = this.getElementsByTagName('span')[1] var val = parseInt(input.value) switch (cls) { case 'add': input.value = val + 1; raduce.innerHTML = '-' break; case 'raduce': if(val>1) { input.value = val - 1; } if(input.value<=1) { raduce.innerHTML = '' } break; default: break; } } }
要加这个getSubTotal(this);