首页 > 解决方案 > 使用@if 语句向元素添加多个类

问题描述

我有以下问题。我正在检查数组是否为空,如果它们是我在表中隐藏特定元素。这个实现只添加了一个类,但是有没有办法在不使用 javascript 的情况下添加多个类?

<table @if(empty($a)) class="hide_a"@endif
    @if(empty($aa)) class="hide_aa"@endif
    @if(empty($aaa)) class="hide_aaa"@endif>

标签: laravellaravel-blade

解决方案


问题是,一个 html 元素只能有一个class属性。只需检查类属性中的值

<table class="{{ empty($a) ? 'hide_a' : '' }} {{ empty($aa) ? 'hide_aa' : '' }} {{ empty($aaa) ? 'hide_aaa' : '' }}">

推荐阅读