我找到了我的答案-绝对的骨头错误!!! :)从PHP包含文件加载价格数字之前带有“ $”符号使jQuery无法计算价格总和!我删除了美元符号,世界一切安好!!! :)谢谢大家的尝试!
我想使用PHP包含文件在span元素中填充价格信息...
如果使用PHP include加载商品价格,则总和将为 不行!如果我将价格硬编码到元素中,则价格 总结工作正常。为什么? ..............
这是jsFiddle的工作方式。问题是当我使用PHP包含文件加载价格数据时,求和停止... https://jsfiddle.net/luenib/k2nj6d8w/
<!--------------------------- ITEM 1l ---------------------------->
<fieldset class="item-fieldset" form="itemsForm">
<?php include "inc/config/ladies_items_config.php"; ?>
<legend><?php echo $itm1l ?></legend>
<div class="item_image_container">
<a href="<?php echo $img1l_full_lnk ?>" target="_blank">
<img class="item_image" src="<?php echo $img1l_82px_lnk ?>" /></a>
<span class="click_full_image">Click for full size</span>
</div><!-- ITEM_IMAGE div CLOSE -->
<table class="inputs" border="1" cellspacing="1">
<tbody>
<tr class="gridaddrows">
<td colspan="8" class="radius">
<div class="itemdesc"><?php echo $des1l ?></div>
</td>
</tr>
<tr class="gridrows">
<td class="gridtitle"><?php echo $itm1l_size_xs ?></td>
<td class="gridtitle"><?php echo $itm1l_size_sm ?></td>
<td class="gridtitle"><?php echo $itm1l_size_md ?></td>
<td class="gridtitle"><?php echo $itm1l_size_lg ?></td>
<td class="gridtitle"><?php echo $itm1l_size_xl ?></td>
<td class="gridtitle"><?php echo $itm1l_size_xx ?></td>
<td class="gridtitle">Total Pcs</td>
</tr>
<tr>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_xs_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_xs_visi ?>"><?php
echo $price1l ?></span></td>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_sm_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_sm_visi ?>"><?php
echo $price1l ?></span></td>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_md_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_md_visi ?>"><?php
echo $price1l ?></span></td>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_lg_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_lg_visi ?>"><?php
echo $price1l ?></span></td>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_xl_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_xl_visi ?>"><?php
echo $price1l ?></span></td>
<td><input type="number" class="item1l" min="0" max="288" name="item1lQty[]"
placeholder="Qty" autocomplete="off" style="visibility: <?php echo
$itm1l_xx_visi ?>"><br>
<span class="price" style="visibility: <?php echo $itm1l_xx_visi ?>"><?php
echo $price1l_xx ?></span></td>
<td><input type="number" class="item1ltotal" placeholder="0" readonly/><br>
$<span id='total'>0.00</span></td>
</tr>
</tbody>
</table>
</fieldset>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="js/custom.js"></script>
</body>
</html>
以下代码位于“ custom.js”文件中
// ********** LADIES PRICE TOTAL **********
$(document).on('click keyup', '.item1l', function() {
$('.item1l').each(function() {
var qty = parseInt($('.item1ltotal').val(), 10);
var price = parseFloat($('.price').text()).toFixed(2);
$('#total').text((qty * price ? qty * price : 0).toFixed(2));
// console.log(price);
// ********** LADIES QUANTITY TOTAL **********
var sum = 0;
$(".item1l").each(function() {
sum += +$(this).val();
});
$(".item1ltotal").val(sum);
});
});