【发布时间】:2015-07-19 00:26:31
【问题描述】:
我有一个问题,我需要在点击链接时显示/隐藏每列的colspan。
也就是说,我有很多条记录,当你点击任何特定的时候,需要在colspan上显示这个信息,当点击另一个记录时隐藏之前点击的记录。
我的 HTML 代码:
<table class="table table-condensed table-bordered table-hover text-center">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Price</th>
<th>Date</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<?php foreach ($products as $row): ?>
<tr>
<td>1</td>
<td>Product 1</td>
<td>10000</td>
<td>Date</td>
<td><a href="#" class="show" id="1">Show details</a></td>
</tr>
<tr>
<td>2</td>
<td>Product 2</td>
<td>100</td>
<td>Date</td>
<td><a href="#" class="show" id="2">Show details</a></td>
</tr>
<tr>
<td colspan="5">Details of selected product</td>
</tr>
<?php endforeach; ?>
<tbody>
</table>
我有这个代码,但总是给我带来第一条记录:
$('.show').click(function(){
$(this).parent().parent().next().toggle('slow');
var id = $(this).attr('id');
$('td #colspanid').append(id); //show id
return false;
});
【问题讨论】:
-
在浏览器中发布
HTML就好了!! -
不知道从哪里开始,我对jQuery的掌握非常基础。
-
@CristianMezaBustos 那么你应该从学习 jQuery 基础开始。文档、书籍、教程等。
-
至少有一些记录可以在 jsfiddle 中进行测试
-
准备好了,很抱歉我在创建问题时犯了错误。问候!!。
标签: javascript php jquery html mysql