慕莱坞4462739
2017-05-03 22:01
num.onclick = function (e) {
e = e || window.event;
var el = e.srcElement;
var cls = el.className;
var input = this.getElementsByTagName('input'); //取得input的值
var val = parseInt(input.value);
var reduction = this.getElementsByClassName('reduction');
switch (cls) {
case 'plus':
input.value=val+1;
break;
case 'reduction':
input.value=val-1;
break;
default:
break;
}
}
num.onclick = function (e) {//num是哪一行
e = e || window.event;
var el = e.srcElement;
var cls = el.className;
var input = this.getElementsByTagName('input')[1]; //取得input的第几个值
var val = parseInt(input.value);
var reduction = this.getElementsByClassName('reduction');
switch (cls) {
case 'plus':
val++;
input.value=val;
break;
case 'reduction':
val--;
input.value=val;
break;
default:
break;
}
}
用JS实现购物车特效
43236 学习 · 167 问题
相似问题