【发布时间】:2021-02-08 00:32:09
【问题描述】:
我有这个 javascript 来防止数量字段低于 1。我想做的是确保最大数量是 10 并且不能低于 1。
/**
* When using the quantity selector, this can be used to decrease the quantity (be ensuring it won't be lower than 1)
*/
}, {
key: '_decreaseQuantity',
value: function _decreaseQuantity(event, target) {
target.nextElementSibling.value = Math.max(parseInt(target.nextElementSibling.value) - 1, 1);
}
/**
* When using the quantity selector, this can be used to increase the quantity
*/
}, {
key: '_increaseQuantity',
value: function _increaseQuantity(event, target) {
target.previousElementSibling.value = parseInt(target.previousElementSibling.value) + 1;
}
/**
* Make sure the quantity does not go below when manually changed
*/
}, {
key: '_validateQuantity',
value: function _validateQuantity(event, target) {
target.value = Math.max(parseInt(target.value) || 1, 1);
}
}]);
【问题讨论】:
标签: javascript html validation math shopify