【问题标题】:Why is my Quantity Spinner script not working?为什么我的 Quantity Spinner 脚本不起作用?
【发布时间】:2017-08-03 03:25:04
【问题描述】:

数量输入和订单按钮正下方的脚本

<div class="clear" id="dvQty">
  <p class="qty-label">Qty:</p>
  <div class="qty-plus" id="divup">+</div>
  <div class="qty-input">
    <input name="vwquantity" value="1" class="qty-input" type="text">
  </div>
  <div class="qty-minus" id="divdown">-</div>
  <div class="add2cart fl"><input value="Add to Cart" class="ys_primary" title="Add to Cart" type="submit"><input name="vwcatalog" value="bodylogic" type="hidden"><input name="vwitem" value="herbal-select-creme-gallon" type="hidden"></div>

</div>

js

$("#txtQty").numeric();
$("#divup").click(function() {
  var qty = $("#txtQty").val();
  qty++;
  $("#txtQty").val(qty);
});
$("#divdown").click(function() {
  var qty = $("#txtQty").val();
  if(qty > 1) {
    $("#txtQty").val(qty - 1);
  }
});

我没有看到什么?

【问题讨论】:

  • 您的输入没有 ID txtQty

标签: javascript product-quantity


【解决方案1】:

id="txtQty" 添加到您的输入中,因为您调用了$("#txtQty"),替换

<input name="vwquantity" value="1" class="qty-input" type="text">

<input id="txtQty" name="vwquantity" value="1" class="qty-input" type="text">

.numeric() 不是 jQuery 内置函数 去掉它好像没有 jQuery,在你的 html 正文下面添加一行

<script src="https://cdn.jsdelivr.net/jquery/1.12.4/jquery.min.js"></script>

【讨论】:

  • 谢谢,ewwink。必须制作输入“vwquantity”的 ID,因为这是购物车脚本需要查看的内容,并且在这个平台上,我无权访问购物车服务器。我确定我已经在 head 标签中调用了 jQuery。所以确定我从来没有检查过。但你做到了。我很感激。解决这些问题后一切正常。
猜你喜欢
  • 2016-11-03
  • 2012-10-07
  • 2015-10-14
  • 1970-01-01
  • 1970-01-01
  • 2017-05-30
  • 2013-04-29
  • 2010-11-16
相关资源
最近更新 更多