我有一些标签,默认情况下我要使第一个标签处于活动状态。现在,仅当我按下选项卡时,该按钮才处于活动状态。我想默认启用第一个标签。
这是我的代码:
<ul class="nav nav-tabs">
<?php $count_contact = 0; ?>
@foreach($user->contact as $contact)
<li class=<?php if($count_user == 0){ echo "active"; } ?> >
<a data-toggle="tab" href="#contact<?php echo $count_contact++; ?>">
<?php $img = asset('thumbnail').'/'.$contact->profile_picture; ?>
@if(@getimagesize($img))
<img class="img-circle noticeboard-profile-picture" src="{{ url('ass/50/50?'.$img) }}" alt=""></a>
@else
<?php $img = "assets/img/user.jpg"; ?>
<img class="hover-effect" alt="" src="{{ url('ass/54/54?'.$img) }}" width="50px">
@endif
</a>
</li>
@endforeach
</ul>
第一个标签的ID为contact0。
答案 0 :(得分:2)
也许您要使用的是$count_contact
而不是$count_user
。尝试更改:
<li class=<?php if($count_user == 0){ echo "active"; } ?> >
收件人:
<li class=<?php if($count_contact == 0){ echo "active"; } ?> >
答案 1 :(得分:1)
Blade提供$loop
变量,您可以在循环中访问该变量。因此,将您的代码更改为此:
<ul class="nav nav-tabs">
<?php $count_contact = 0; ?>
@foreach($user->contact as $contact)
<li @if($loop->first) class="active" @endif>
<a data-toggle="tab" href="#contact<?php echo $count_contact++; ?>">
<?php $img = asset('thumbnail').'/'.$contact->profile_picture; ?>
@if(@getimagesize($img))
<img class="img-circle noticeboard-profile-picture" src="{{ url('ass/50/50?'.$img) }}" alt=""></a>
@else
<?php $img = "assets/img/user.jpg"; ?>
<img class="hover-effect" alt="" src="{{ url('ass/54/54?'.$img) }}" width="50px">
@endif
</a>
</li>
@endforeach
</ul>