-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>
确定,但我将建立一个变种SP = $(“#sellingprice”)的使用VAL()| 0; – user7428613
我更新了答案,显示你应该改变它。 – Scovetta
我做了你建议我的改变,但没有改变。它不显示任何错误消息,请再次检查问候语Inders - – user7428613