//点加,小计 for (var i = 0; i < increment.length; i++) { increment[i].index = i; increment[i].onclick = function() { var flag = this.index; var q = quantity[flag]; var p = price[flag].textContent; var s = subtotal[flag]; var newvalue = parseInt(q.value) + 1; q.setAttribute("value", newvalue); s.textContent = (newvalue * parseFloat(p)).toFixed(2); calculateTotal(); }; } //点减,小计 for (var j = 0; j < decrement.length; j++) { decrement[j].index = j; decrement[j].onclick = function() { var flag = this.index; var q = quantity[flag]; var p = price[flag].textContent; var s = subtotal[flag]; if (parseInt(q.value) > 1) { var newvalue = parseInt(q.value) - 1; q.setAttribute("value", newvalue); s.textContent = (newvalue * parseFloat(p)).toFixed(2); calculateTotal(); } }; }根据此代码设初始数量为1
时间: 2024-02-10 07:05:49 浏览: 91
推进值常量 优先级推进值-驱动开发8.IO请求包
如果需要将初始数量设为1,可以在HTML代码中将数量的输入框的value值设置为1,或者在JavaScript代码中将数量的输入框的value属性设置为1,例如:
```javascript
var quantity = document.getElementsByClassName("quantity");
for (var i = 0; i < quantity.length; i++) {
quantity[i].value = 1;
}
```
这样就可以将所有数量的输入框初始值设置为1。
阅读全文