如何在警告消息上显示不同的值?

时间:2017-01-23 06:38:15

标签: jquery html css

我有代码,我希望在警告消息上显示不同的值。如果消息显示为:The dims entered greater than 20STD, 40STD and 40HC Containers, change the mode to bulk,则LCLFCL应替换为值:BULK

JS:

<script type="text/javascript">
$(function () {
    $('.pnm, .price, .subtot, .widtot, .perm, .tottot, .vol, .tot, .vols, .heights, .acts').prop('readonly', true);
    var $tblrows = $("#tblProducts tbody tr");

    $tblrows.each(function (index) {
        var $tblrow = $(this);
        $tblrow.find('.height, .carton, .perm').on('change', function () {
            var carton = $tblrow.find("[name=carton][type=number][min=0]").val();
            var width = $tblrow.find("[name=height][type=number][min=0]").val();
            var perm = $tblrow.find("[name=perm]").val();

            var subTotal =parseFloat(width*0.01, 10) * parseInt(carton, 10);
            var cartons =parseInt(carton, 10);

            if (!isNaN(cartons)) {

                $tblrow.find('.carton').val(cartons.toFixed(0));
                var cartonTotal = 0;

                $(".carton").each(function () {
                    var stval = parseInt($(this).val());
                    cartonTotal += isNaN(stval) ? 0 : stval;
                });

                $('.cartontot').val(cartonTotal.toFixed(0));
            }            
            if (!isNaN(subTotal)) {

                $tblrow.find('.perm').val(subTotal.toFixed(5));
                var grandTotal = 0;

                $(".perm").each(function () {
                    var stval = parseFloat($(this).val());
                    grandTotal += isNaN(stval) ? 0 : stval;
                });

                $('.grdtot').val(grandTotal.toFixed(5));
            }
            $('.grdtot').val(grandTotal.toFixed(5));

            if (grandTotal > 7) {
                $('#result').html('FCL');
            } else if (grandTotal < 7) {
                $('#result').html('LCL');
            }
            else if ('.error') {
                $('#error').html('BULK');
            }
            else if ('.errorlength') {
                $('#errorlength').html('BULK');
            }

            var height = $(this).val();
            var hightOnly = ($(this).attr('class') == 'height') ? height : false;
            var subCalc  =  parseFloat(height);
            if (!isNaN(subCalc)) {
                $tblrow.find('.calcheight').val(subCalc.toFixed(5));
                var calcTotal = 0;
                $(".calcheight").each(function () {
                    var stval = parseFloat($(this).val());
                    calcTotal += isNaN(stval) ? 0 : stval;
                });
                $('.heitot').val(calcTotal.toFixed(5));
            }
            var sp = subCalc;
            hightOnly  =  parseFloat(hightOnly);
            if(hightOnly > 238 && hightOnly < 269) {
                $(this).closest('tr').find('td.error').text('The dims entered greater than 20STD and 40STD Containers, change the mode to bulk');
            }   else if(hightOnly > 269){
                $(this).closest('tr').find('td.error').text('The dims entered greater than 20STD, 40STD and 40HC Containers, change the mode to bulk');
            } else if(hightOnly < 269) {
                $(this).closest('tr').find('td.error').text('');
            }
        }); 
    }); 
});
</script>

HTML:

<table id="tblProducts">
    <tbody>
        <tr>
            <td><input type="text" class="pnm" value="Product One" name="pnm" style="width:120px" /></td>
            <td ><input type="number" oninput="validity.valid||(value='');" class="carton" value="0" name="carton" min="0" maxlength="5" style="width:70px"></td>
            <td><input type="number" oninput="validity.valid||(value='');" class="height" value="0" min="0" name="height" maxlength="5" style="width:80px"/></td>
            <td><input type="number" class="perm" value="" name="perm" style="width:80px"/></td>
            <td class="error" id="error" style="color:red"></td> 
        </tr>
        <tr>
            <td><input type="text" class="pnm" value="Product Second" name="pnm" style="width:120px" /></td>
            <td ><input type="number" oninput="validity.valid||(value='');" class="carton" value="0" name="carton" min="0" maxlength="5" style="width:70px"></td>
            <td><input type="number" oninput="validity.valid||(value='');" class="length" value="0" min="0" name="length" maxlength="5" style="width:80px"/></td>
            <td><input type="number" class="perm" value="" name="perm" style="width:80px"/></td>
            <td class="error" id="errorlength" style="color:red"></td> 
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td></td>
            <td><input type="number" class="cartontot" value="" name="" style="width:70px" readonly/></td>
            <td></td>
            <td><input type="number" class="grdtot" value="" name="" style="width:80px" readonly/></td>
        </tr>
    </tfoot>
    <label id="result" style="color:#03BF03"></label>
 </table>

0 个答案:

没有答案