javascript - 更改数量 javascript
问题描述
我有一个 javascript 代码可以更改 Magento 中产品的数量,但我有一个问题。当我减少数量时,最新值为 0 的值为 -1。如何停止减少按钮以仅保留在 0 值上?
谢谢
/********************* Qty Holder **************************/
$(document).on("click", ".qtyplus", function(e) {
// Stop acting like a button
e.preventDefault();
// Get its current value
var currentVal = parseInt($(this).parents('.qty-changer').find('input.input-text.qty').val());
// If is not undefined
if (!isNaN(currentVal)) {
// Increment
$(this).parents('.qty-changer').find('input.input-text.qty').val(currentVal + 1);
$(this).parents('.qty-changer').find('.update-cart-item').show();
} else {
// Otherwise put a 0 there
$(this).parents('.qty-changer').find('input.input-text.qty').val(1);
}
});
// This button will decrement the value till 0
$(document).on("click", ".qtyminus", function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
fieldName = $(this).attr('field');
// Get its current value
var currentVal = parseInt($(this).parents('.qty-changer').find('input.input-text.qty').val());
// If it isn't undefined or its greater than 0
if (!isNaN(currentVal) && currentVal > 1) {
// Decrement one
$(this).parents('.qty-changer').find('input.input-text.qty').val(currentVal - 1);
$(this).parents('.qty-changer').find('.update-cart-item').show();
} else {
// Otherwise put a 0 there
$(this).parents('.qty-changer').find('input.input-text.qty').val(1);
}
});
解决方案
推荐阅读
- docker - 如何使运行 Windows 主机的 docker 容器中的端口可用于本地网络
- python - 如何根据熊猫另一列中的条件生成具有值的新列
- javascript - 如何在不单击任何按钮并获取用户响应的情况下从 C# 代码后面显示带有是和否选项的弹出窗口
- swift - 如何在 iOS 中将 Firebase 推送通知从设备发送到设备
- list - 如何通过列表
剑道网格读取() - dictionary - Delphi TDictionary 与泛型
- powershell - 使用 Powershell 编辑 IIS 自定义响应标头
- xslt - 如何在 XSLT 的 for 循环中获取下一个节点的子值
- java - 如何将包含“e +”字符串转换为长字符串?
- c# - 如何对OwnsMany 集合进行分页?