• 选择下拉列表,出现不同数据,并计算


    点击下拉框,出现缴纳电费,水费,燃气费三个选项。选择其一,下边对应的单价改变,选择数量,进行计算。

    //结构
    <select name="type" class="form-control feeName"
    									onchange="show_sub(this.options[this.options.selectedIndex].value)">
    									
    									<c:forEach items="${datas}" var="da">
    									<option value="${da.type}" price="${da.val}">${da.name}</option>
    									</c:forEach>
    	
    								</select>
    

      

    //计算 

    var firstPrice = parseFloat($(".feeName").children("option:first-child").attr("price"));
    $("#price").val(firstPrice.toFixed(2));
    var num = parseInt($("#num").val());
    var money = firstPrice*num;
    $("#totalPrice").text(money.toFixed(2));
    add();

    //选择3个选项获取不同的单价
    function show_sub(v) {
    parseInt($("#num").val(1));
    if (v == 1) {
    var firstPrice = parseFloat($(".feeName").children("option:first-child").attr("price"));
    var money = firstPrice*num;
    $("#price").val(firstPrice.toFixed(2));
    $("#totalPrice").text(money.toFixed(2));
    }
    if (v == 2) {
    var secondPrice = parseFloat($(".feeName").children("option:nth-child(2)").attr("price"));
    var money = secondPrice*num;
    $("#price").val(secondPrice.toFixed(2));
    $("#totalPrice").text(money.toFixed(2));

    }
    if (v == 3) {
    var lastPrice = parseFloat($(".feeName").children("option:last-child").attr("price"));
    var money = lastPrice*num;
    $("#price").val(lastPrice.toFixed(2));
    $("#totalPrice").text(money.toFixed(2));
    }
    }

    //购物车加减
    function add() {

    $(".addNum").click(function() {
    var numTextVal = $(this).parent().find("#num");
    numTextVal.val(parseInt(numTextVal.val()) + 1);
    setTotal();
    });

    $(".minNum").click(function() {
    var numTextVal = $(this).parent().find("#num");
    numTextVal.val(parseInt(numTextVal.val()) - 1);
    if (parseInt(numTextVal.val()) < 1) {
    numTextVal.val(1);
    };
    setTotal();
    });

    function setTotal() {
    var s = 0;
    $("#formData").each(function() {
    s += parseInt($(this).find('input[id*=num]').val()) * parseFloat($(this).find('input[id*=price]').val());
    });

    $("#totalPrice").text(s.toFixed(2));
    };
    setTotal();

    };

    //输完数量自动计算
    $(function(){
    $("#num").change(function(){
    $("#totalPrice").text($(this).val()*$("#price").val());

    $(".mT1").each(function(){
    var money = parseInt($(this).text());
    function toThousands(num) {
    var result = [ ], counter = 0;
    num = (num || 0).toString().split('');
    for (var i = num.length - 1; i >= 0; i--) {
    counter++;
    result.unshift(num[i]);
    if (!(counter % 3) && i != 0) { result.unshift(','); }
    }
    return result.join('');
    }
    $(this).text(toThousands(money));
    });
    });
    })

      

  • 相关阅读:
    地图刷新方法一二三。
    AE常用代码(标注要素、AE中画带箭头的线、如何获得投影坐标、参考坐标、投影方式、FeatureCount注意事项)
    转:Windows任务计划实现自动执行ArcGIS相关功能
    解决 Oracle em 无法打开的问题
    设置ORACLE数据库游标大小
    ArcSDE数据迁移方法实践说明
    转:湖南省地理信息关联单位
    转:C# Autocad 关闭所有有色斑的图层
    转:实体ToolTip显示XData
    ArcGIS Server 10 服务器要求
  • 原文地址:https://www.cnblogs.com/TigerZhang-home/p/7459813.html
Copyright © 2020-2023  润新知