我正在尝试将增量/减量按钮添加到数量字段。因此,当用户按下右箭头时,数量字段中的数量将更新1.这是我的代码,我得到一个未捕获的ReferenceError:在HTMLAnchorElement.onclick中没有定义incrementQty,我不知道如何继续。函数存在,我传递动态表单id?
<script type=”text/javascript”>
function decrementQty(id) {
var val = parseInt($('#' + id).getValue());
if(val != 1)
document.getElementById(id).value = val - 1;
}
function incrementQty(id) {
var val = parseInt($('#' + id).getValue());
document.getElementById(id).value = val + 1;
}
</script>
<input id="cart-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-qty"
name="cart[<?php /* @escapeNotVerified */ echo $_item->getId() ?>][qty]"
data-cart-item-id="<?php /* @escapeNotVerified */ echo $_item->getSku() ?>"
value="<?php /* @escapeNotVerified */ echo $block->getQty() ?>"
type="number"
size="4"
title="<?php echo $block->escapeHtml(__('Qty')); ?>"
class="input-text qty"
maxlength="12"
data-validate="{required:true,'validate-greater-than-zero':true}"
data-role="cart-item-qty"/>
<a class="pic arrow-right qty" href="javascript:void(0);" onclick="incrementQty('cart-<?php /* @escapeNotVerified */ echo $_item->getId() ?>-qty');"></a>
呈现HTML
<input id="cart-502-qty"
name="cart[502][qty]"
data-cart-item-id="7640149080453"
value="8"
type="number"
size="4"
title="Qty"
class="input-text qty"
maxlength="12"
data-validate="{required:true,'validate-greater-than-zero':true}"
data-role="cart-item-qty"/>
<a class="pic arrow-right qty" href="javascript:void(0);" onclick="incrementQty('cart-502-qty');"></a>
答案 0 :(得分:0)
<script>
function showHint(str){
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
$.ceAjax('request', fn_url('paysrk.paymod'), {
method: 'get',
caching: false,
hidden:true,
data: { 'amount': str },
callback: function(data){
alert(data);
}
});
}
}
</script>