2017-01-17 59 views
-1

我有一个jQuery代码表经过if else条件与固定值比较后显示的错误消息,但它不工作,我想if else条件与它的表输入类型的值。如果条件与表输入字段

任何人都可以检查这个&让我知道什么是错的?谢谢。

<script type="text/javascript"> 
    $(function() { 
    $('.pnm, .price, .subtot, .widtot, .perm, .tottot, .vol, .tot, .vols, .widths, .depths, .heights, .acts, .heitot').prop('readonly', true); 
    var $tblrows = $("#tblProducts tbody tr"); 
    $tblrows.each(function (index) { 
    var $tblrow = $(this); 
    $tblrow.find('.width, .carton, .depth, .height, .act, .tot, .vol, .perm').on('change', function() { 
    var height = $tblrow.find("[name=height][type=number][min=0]").val(); 
    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)); 
    } 
    }); 
    }); 
    }); 
</script> 

<table id="tblProducts"> 

<script type="text/javascript"> 
    var sp = $('#sellingprice').val() | 0; 
    if (sp >= 2.38) { 
     <?php echo "error with 20 STD and error with 40 STD"; ?> 
    } 
    else if (sp >= 2.69){ 
     <?php echo "error with 40 HC"; ?> 
    } 
    else 
    { 
    <?php echo ""; ?> 
    } 
</script> 
<tbody> 
    <tr> 
    <td><input type="text" class="pnm" value="First One" name="pnm" style="width:120px" /></td> 

    <td><input type="number" oninput="validity.valid||(value='');" id="sellingprice" class="height" value="0" name="height" min="0" maxlength="5" style="width:100px"/></td>  
    <td><input type="number" class="calcheight" value="" name="calcheight" style="width:100px" readonly/></td> 
    </tr> 
    <tr> 
    <td><input type="text" class="pnm" value="Second One" name="pnm" style="width:120px" /></td> 

    <td><input type="number" oninput="validity.valid||(value='');" id="sellingprice" class="height" value="0" name="height" min="0" maxlength="5" style="width:100px"/></td> 
    <td><input type="number" class="calcheight" value="" name="calcheight" style="width:100px" readonly/></td> 
    </tr> 
</tbody> 
<tfoot> 
    <tr> 
    <td></td> 
    <td></td> 
    <td><input type="number" class="heitot" value="" name="" style="width:100px" readonly/></td> 
    </tr> 
</tfoot> 
</table> 

回答

0

你有PHP代码在JavaScript函数中运行,除非你在做一些古怪的服务器端,不会做你想做的事情。相反,将这些<?php echo ... ?>行更改为alert(...),至少要对其进行测试。

其次,你必须:

var sp = $('#sellingprice').val() | 0; 

你会想改变这种单一|或双||。单|是二进制“或”不符合逻辑“或”:

var sp = $('#sellingprice').val() || 0; 
+0

确定,但我将建立一个变种SP = $(“#sellingprice”)的使用VAL()| 0; – user7428613

+0

我更新了答案,显示你应该改变它。 – Scovetta

+0

我做了你建议我的改变,但没有改变。它不显示任何错误消息,请再次检查问候语Inders - – user7428613

相关问题