javascript - Laravel 5.1 - 如果变量有值则隐藏部分 (javascript)

标签 javascript php html laravel

我正在使用 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/

相关文章:

javascript - 从包含键路径的字符串中获取 json 值

javascript - 将 JSON 数据渲染到 html 表 Angularjs

javascript - 带圆 Angular 的 Canvas clearRect

javascript - MomentJS 在格式化时更改日期值?

php - 无法过滤空格,查询返回所有用户

html - 什么是 "data-effect"属性?

javascript - 单击搜索框时删除类

javascript - 如何在tensorflow js中找到张量的形状?

javascript - 按每个数组中包含的元素对数组数组进行排序

php - javascript一次获取多个属性onchange