我正在使用 laravel 5.1(电子商务),我将一些变量传递给我的 View :
我的变量“$price_coupon”可以是“0”或“>0”,例如10,20等...
我想隐藏这个:
<tr class="cart-subtotal" id="coupon">
<th>Coupon:</th>
<td>
<span class="amount">€{{ number_format($price_coupon, 2) }}</span>
</td>
</tr>
如果 $price_coupon = 0 并且显示 IF $price_coupon > 0。
我认为这是 javascript 的功能,对吗?怎么办呢?感谢您的帮助!
这是我查看的所有表格:order-detail.php
<table>
<tbody>
<tr class="cart-subtotal">
<th>Subtotale:</th>
<td><span class="amount">€{{ number_format($total, 2) }}</span></td>
</tr>
<tr class="cart-subtotal" id="coupon">
<th>Coupon:</th>
<td><span class="amount">€{{ number_format($price_coupon, 2) }}</span></td>
</tr>
<tr class="shipping">
<th>shipping:</th>
<td>€<input type="text" id="price_ship" name="price_ship" class="price_ship" disabled /></td>
</tr>
<tr class="order-total">
<th>Totale Ordine:</th>
<td><strong><span class="amount">
€<input type="text" id="total_ship" name="total_ship" class="total_ship" disabled />
</span></strong> </td>
</tr>
</tbody>
</table>
我纠正了这个问题:我也使用 Blade 模板。
最佳答案
在 JavaScript (jQuery) 中
if( parseInt( $('.amount').text() ) <= 0 ){
$('.amount').closest('tr').css('display', 'none');
}else{
$('.amount').closest('tr').css('display', '');
}
您还可以使用
parseFloat()
因为它是货币并且具有小数值。但由于四舍五入的原因,这只对 0.4
或更小的值有意义。
这个奇怪的东西是什么鲍勃€
磅?我们只是在池塘的我这边使用 $
。让我想知道他们是否为 jQuery €('.class')
执行此操作,为 php €var;
执行此操作,嗯...
我实际上有一个英国 friend ,长话短说,他回到“旧”世界探望他的家人,并说他得到了一部 100 磅的手机。我对他说,哇,这太重了,哈哈。
关于javascript - Laravel 5.1 - 如果变量有值则隐藏部分 (javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594028/