dpwgzi7987 2015-07-09 13:04
浏览 43
已采纳

如果可见则添加div选项以在结尾处获得总计

I have a list of divs that pull integer values from a SQL table. All of those divs are not visible unless a certain selection is made in the form. I want to create another div that sum's all visible divs at the end for the user to see their ending total.

Edit: The below code is now what I have but it totals all divs not ones that are only visible.

$("#clicky").click(function () {
    var total = 0;
$('.equipmentmprice').each(function() {
    total += parseFloat($(this).find('span.price').eq(0).text());
});

$('#totalamount').text('Total is: $' + total);
});

I know I can use javascript or jquery but I'm not sure really where to start.

Here is an example of one of my divs:

<div class="largeplantablefive equipmentmprice" style="display:none">
<?php
    $connection = mysql_connect('localhost', 'test', 'testone');
    mysql_connect('localhost', 'test', 'testone');
    mysql_select_db('test');
    $queryone = mysql_query("SELECT price FROM pricing WHERE value = 'plantablefive'");
    $query_row = mysql_fetch_array($queryone);
    echo "Plan Tables: $" . ($query_row[price]) . "<span style='color:red'><i> Price does not include cost of the physical table.</i></span>";
?>  
</div>

Right now I'm thinking I will have to create another div or other tag inside the echo statement where the value equals $query_row.

  • 写回答

2条回答 默认 最新

  • dse3168 2015-07-15 17:44
    关注

    Found the answer with some searching and using multiple suggestions combining it into my own. Below is what I did and the answer. Just added the :visible into the class select.

    $("#clicky").click(function () {
        var total = 0;
    $('.equipmentmprice:visible').each(function() {
        total += parseFloat($(this).find('span.price').eq(0).text());
    });
    
    $('#totalamount').text('Total is: $' + total);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么