我希望在结帐页面上为数量输入添加加号和减号按钮。当输入更新时,javascript函数被称为更新总成本。
我添加了更新输入框的按钮和jquery,但我需要帮助更新成本的javascript函数。
以下是按钮的代码:
<button class='MIN'>-</button>
<input id='qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>' class="InputText" name='qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>' type="text" size="1" style="width:25px;" value='<c:out value="${quickCartOrderItemQuantity}"/>' style="text-align:center" onkeydown="JavaScript:setCurrentId('qty_<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>'); CheckoutHelperJS.updateCartWait(this, this.value, '<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>',event)" />
<button class='PLUS'>+</button>
这是按钮的jQuery
$(".PLUS, .MIN").click(function(){
var itemVal = parseInt($(this).siblings(".InputText").val());
if ($(this).hasClass('MIN'))
itemVal--;
else
itemVal++;
$(this).siblings(".InputText").val(itemVal);
});
以下是updateCartWait函数的代码:
updateCartWait:function(quantityBox, oldQuantity, orderItemId,event) {
if(event.keyCode == dojo.keys.TAB)return;
if(!this.isAjaxCheckOut()){
return;
}
//Key pressed.. update the flag
if(this.keyPressCount[orderItemId] == null && isNaN(this.keyPressCount[orderItemId])){
this.keyPressCount[orderItemId] = 0;
}
this.keyPressCount[orderItemId] = parseInt(this.keyPressCount[orderItemId]) + 1;
setTimeout(dojo.hitch(this,"checkInventoryAndUpdateCart",quantityBox,oldQuantity,orderItemId,this.keyPressCount[orderItemId]),this.updateWaitTimeOut);
}
这是checkInventoryAndUpdateCart
checkInventoryAndUpdateCart:function(quantityBox, oldQuantity, orderItemId, keyPressCountValue) {
// Get quantities and status
var inventoryStatusControl = dojo.byId("orderItem_inventoryStatus_" + orderItemId);
var clearanceStatusControl = dojo.byId("orderItem_clearanceStatus_" + orderItemId);
var availableQuantityControl = dojo.byId("orderItem_availableQuantity_" + orderItemId);
var inventoryStatus = '';
if (inventoryStatusControl && inventoryStatusControl.innerHTML != '') inventoryStatus = inventoryStatusControl.innerHTML;
var clearanceStatus = 'false';
if (clearanceStatusControl && clearanceStatusControl.innerHTML != '') clearanceStatus = clearanceStatusControl.innerHTML;
var availableQuantity = 0;
if (availableQuantityControl && availableQuantityControl.innerHTML != '') availableQuantity = parseInt(availableQuantityControl.innerHTML);
var quantity = parseInt(quantityBox.value);
if (inventoryStatus == 'Discontinued') {
alert('This product is discontinued and can not be ordered.');
return;
}
if (clearanceStatus == 'true') {
if (availableQuantity < quantity) {
this.showClearanceItemDialog(orderItemId, quantity, oldQuantity, availableQuantity, keyPressCountValue);
} else {
this.updateCart(quantity, orderItemId, keyPressCountValue);
}
return;
}
if (availableQuantity < quantity) {
if (availableQuantity == 0) {
this.showNoStockDialog(orderItemId, quantity, oldQuantity, availableQuantity, keyPressCountValue);
} else {
this.showInsufficientStockDialog(orderItemId, quantity, oldQuantity, availableQuantity, keyPressCountValue);
}
} else {
this.updateCart(quantity, orderItemId, keyPressCountValue);
}
有人可以帮忙吗?
答案 0 :(得分:0)
我相信我通过正确传递值来实现它!
<button class='MIN' onclick="JavaScript:setCurrentId('qty_<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>'); CheckoutHelperJS.updateCartWait(document.getElementById('qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>'), document.getElementById('qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>').value, '<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>',event)">-</button>
<input id='qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>' class="InputText" name='qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>' type="text" size="1" style="width:25px;" value='<c:out value="${quickCartOrderItemQuantity}"/>' style="text-align:center" onkeydown="JavaScript:setCurrentId('qty_<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>'); CheckoutHelperJS.updateCartWait(this, this.value, '<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>',event)" />
<button class='PLUS' onclick="JavaScript:setCurrentId('qty_<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>'); CheckoutHelperJS.updateCartWait(document.getElementById('qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>'), document.getElementById('qty_<c:out value="${orderItem.orderItemIdentifier.uniqueID}"/>').value, '<c:out value='${orderItem.orderItemIdentifier.uniqueID}'/>',event)">+</button>