laravel - 使用@if 语句向元素添加多个类
问题描述
我有以下问题。我正在检查数组是否为空,如果它们是我在表中隐藏特定元素。这个实现只添加了一个类,但是有没有办法在不使用 javascript 的情况下添加多个类?
<table @if(empty($a)) class="hide_a"@endif
@if(empty($aa)) class="hide_aa"@endif
@if(empty($aaa)) class="hide_aaa"@endif>
解决方案
问题是,一个 html 元素只能有一个class
属性。只需检查类属性中的值
<table class="{{ empty($a) ? 'hide_a' : '' }} {{ empty($aa) ? 'hide_aa' : '' }} {{ empty($aaa) ? 'hide_aaa' : '' }}">
推荐阅读
- arrays - 将多个单元格的公式形成连接到一个单元格中
- django - pre_save 后保存模型会失败吗?
- teamcity - 是否可以使用不可用的 VCS 根运行 TeamCity 构建?
- pandas - 从 S3 读取时 AWS Lambda 函数出错
- android - 如果我在从 android studio 推送时在 github 中使用正确的凭据登录,为什么会出现访问被拒绝错误
- discord.js - 如何检查消息是否包含表情符号 discord.js
- sql - 如何检查列表中的任何项目是否包含在列名中?- 快速 SQL
- elasticsearch - “原因”:“[匹配] 格式错误的查询,应为 [END_OBJECT],但找到 [FIELD_NAME]”
- reactjs - react prop在子组件中未定义
- python - 即使已经添加了模式、repl 和字符串,为什么 re.sub 也不替换任何出现