JQuery:计算插件不计算总价

发布于 2025-01-08 22:33:39 字数 1608 浏览 0 评论 0原文

:插件 主页:链接

:javascript

  $("[id^=total_price_ht]").calc(
    // the equation to use for the calculation
    "qty * price",
    {
      qty: $("[id^=unit_quantity_]"),
      price: $("[id^=unit_price_ht_]")
    },
    function (s){
      // return the number as a dollar amount
      return "$" + s.toFixed(2);
    }
  );

:html

<tr id="lines[0]">
  <td>
    <input id="0" type="checkbox" class="hiddenCheckbox">
    <label for="0" class="prettyCheckbox checkbox list"><span class="holderWrap" style="width: 18px; height: 19px; "><span class="holder" style="width: 18px; "></span></span></label>
  </td>
  <td>
    <input class="required" name="lines[0][title]" placeholder="Title" type="text">
  </td>
  <td>
    <input name="lines[0][description]" placeholder="Description" type="text">
  </td>
  <td>
    <input class="required" id="unit_quantity_0" name="lines[0][quantity]" placeholder="Quantité" type="text" value="0,00">
  </td>
  <td>
    <input class="required" id="unit_price_ht_0" name="lines[0][unit_price_ht]" placeholder="Prix unit. HT" type="text" value="0,00">
  </td>
  <td class="price" id="total_price_ht_0">$0.00</td>
</tr>

页面加载后,我可以在total_price_ht字段中看到“$0.00”,但当我更改数量或价格时,它的值不会改变。

我做错了什么吗?

:plugin
Homepage: Link.

:javascript

  $("[id^=total_price_ht]").calc(
    // the equation to use for the calculation
    "qty * price",
    {
      qty: $("[id^=unit_quantity_]"),
      price: $("[id^=unit_price_ht_]")
    },
    function (s){
      // return the number as a dollar amount
      return "$" + s.toFixed(2);
    }
  );

:html

<tr id="lines[0]">
  <td>
    <input id="0" type="checkbox" class="hiddenCheckbox">
    <label for="0" class="prettyCheckbox checkbox list"><span class="holderWrap" style="width: 18px; height: 19px; "><span class="holder" style="width: 18px; "></span></span></label>
  </td>
  <td>
    <input class="required" name="lines[0][title]" placeholder="Title" type="text">
  </td>
  <td>
    <input name="lines[0][description]" placeholder="Description" type="text">
  </td>
  <td>
    <input class="required" id="unit_quantity_0" name="lines[0][quantity]" placeholder="Quantité" type="text" value="0,00">
  </td>
  <td>
    <input class="required" id="unit_price_ht_0" name="lines[0][unit_price_ht]" placeholder="Prix unit. HT" type="text" value="0,00">
  </td>
  <td class="price" id="total_price_ht_0">$0.00</td>
</tr>

Once the page loads, I can see '$0.00" in the total_price_ht field but it's value doesn't get changed when I change the quantity or the price.

What am I doing wrong? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2025-01-15 22:33:39

我认为每次要重新计算总计时都需要调用 calc 插件:

$("[id^='unit_quantity_'], [id^='unit_price_ht_']").keyup(recalc);


function recalc() {

    $("[id^='total_price_ht']").calc(
    // the equation to use for the calculation
    "qty * price", {
        bind: "keyup",
        qty: $("[id^='unit_quantity_']"),
        price: $("[id^='unit_price_ht_']")
    }, function(s) {
        // return the number as a dollar amount
        return "$" + s.toFixed(2);
    });
}

recalc();

示例: http://jsfiddle.net/upEZW/

I think you need to call the calc plugin every time you want to recalculate the total:

$("[id^='unit_quantity_'], [id^='unit_price_ht_']").keyup(recalc);


function recalc() {

    $("[id^='total_price_ht']").calc(
    // the equation to use for the calculation
    "qty * price", {
        bind: "keyup",
        qty: $("[id^='unit_quantity_']"),
        price: $("[id^='unit_price_ht_']")
    }, function(s) {
        // return the number as a dollar amount
        return "$" + s.toFixed(2);
    });
}

recalc();

Example: http://jsfiddle.net/upEZW/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文