【发布时间】:2017-01-24 13:01:39
【问题描述】:
我希望将 jQuery 应用于 foreach 循环的每个实例,但只对点击的元素进行操作。
php foreach 循环如下:
@foreach ($entries as $entry)
<?php $row = DB::table('workout_trainings')->where('date', $entry->format('Y-m-d'))->where('user_id', Auth::user()->id)->count(); ?>
<tr style="border-top: 2px solid black;">
<th rowspan={{$row}}><p>{{ $entry->format('l- d/m/Y') }}</p>
<button class="btn btn-default" id="goals_btn">Goals</button>
<button class="btn btn-default" id="logs_btn">Log Workout</button>
</th>
<?php $ws = DB::table('workout_trainings')->where('date', $entry->format('Y-m-d'))->where('user_id', Auth::user()->id)->get(); ?>
@foreach ($ws as $w)
<td>{{$w->exercise}}</td>
<td>{{$w->weight}}</td>
<td>{{$w->sets}}</td>
<td>{{$w->reps}}</td>
</tr>
@endforeach
<tr id="goals">
<td colspan='5'>.</td>
</tr>
<tr id="logs">
<td colspan='5'>.</td>
</tr>
@endforeach
</tbody>
</table>
<?php echo $entries->setPath('')->render(); ?>
我的 jQuery 很简单:
$(document).ready(function(){
$("#goals").css("display","none");
$("#goals_btn").click(function(){
$("#goals").toggle(200);
});
});
这显然适用于顶部项目。
更新
星期三不工作,但在本例中星期四和星期五工作。
谢谢
【问题讨论】:
标签: javascript jquery foreach