-2

我试图在一个表格中总结一些值,我没有设法得到任何地方:

如您所见,有 3 个复选框、3 个单选按钮和 1 个选择下拉菜单

我需要对选定的复选框求和,乘以其中一个单选值并在最后求和所选框中的值。不知道该怎么做:/

我可以将结果保存在对象中吗?不是 json 对象,而是 javascript

<div class="reciright">
        <form id="formi">
        <div class="recil">
            <span class="ltitle">Extras incluídos:</span>
            <div class="recheck"><input class="acc1" type="checkbox" name="vehicle" value="0.4" /> Caixa original</div>
            <div class="recheck"><input class="acc2" type="checkbox" name="vehicle" value="1" /> Cabo e carregador</div>
            <div class="recheck"><input class="acc3" type="checkbox" name="vehicle" value="3" /> Auscultadores</div>

            <span class="ltitle">Estado Geral:</span>
            <div class="recheck"><input type="radio" name="vehicle" value="0.5" /> 100% Funcional</div>
            <div class="recheck"><input type="radio" name="vehicle" value="0.4" /> Funcional mas não a 100%</div>
            <div class="recheck"><input type="radio" name="vehicle" value="0.3" /> Avariado</div>


        </div>

        <div class="recir">
            <span class="ltitle">Dados do Equipamento:</span>
            <div class="recampos">N.de Serie</div> <input class="inputix" type="text" name="fname" id="nserie">
            <p><div class="recampos">Modelo:</div><select class="selectit" id="modelo">
            <option value="50">iPad 2 wifi</option>
            <option value="20">iPad 1</option>
            <option value="10">iPad 2</option>
            <option value="1">iPad 3</option>
        </select></p>

            <div class="recampos2">Breve descricao do equipamento</div>
            <textarea rows="3" cols="50" class="recitextarea"></textarea>

        </div>
        <div class="icecream"></div>
        </form>
    </div>
4

1 回答 1

1

可能是这样的:

$("#modelo, [type='checkbox'], [type='radio']").on('change', function() {
    var boxvalue = 0,
        boxes = $("[type='checkbox']", "#formi").filter(':checked'),
        radios = parseFloat($("[type='radio']").filter(':checked').val()) || 1,
        dropdown = parseFloat($("#modelo").val()) || 1;

    $.each(boxes, function() {
        boxvalue+=parseFloat(this.value)||0;
    });

    var sum = (boxvalue * radios) * dropdown;

    $("#nserie").val(sum);
});

小提琴 ​</p>

于 2012-07-28T19:20:22.860 回答