Bootstrap:Accordion Row:当有多个行时更改展开 - 折叠图标
问题描述:
我有一张带有一些手风琴行的表。 我想更改行上的展开合拢图标expand-collapse 我成功了1行。但是,当我尝试了多行,我的代码工作不好,发生冲突与其他行Bootstrap:Accordion Row:当有多个行时更改展开 - 折叠图标
请帮我,如果有人是有解决方案
var flag = true;
$('.togglebutton').click(function() {
if (flag == true) {
this.getElementsByTagName('img')[0].src = "../images/minus.png";
flag = false;
} else {
this.getElementsByTagName('img')[0].src = "../images/plus.png";
flag = true;
}
})
<tr class="clickable apply-max-width">
<td class="table-tr1-td1 togglebutton"><b aria-hidden="true" data-toggle="collapse" data-target="#accordion"><img src="../images/plus.png"/></b></td>
<td>[email protected]</td>
<td colspan="2">WD100165</td>
<td>2/1/2017</td>
<td>YES</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="2">
<div id="accordion" class="accordion collapse data-found">
<table class="table table-striped data-table-inner-disabled div-found">
<thead>
<tr>
<th></th>
<th class="">Application</th>
<th class="">App Role</th>
<th>Workflow Status</th>
</tr>
</thead>
<tbody>
<tr>
<td class="application-User-inv"><img src="../images/delete_1.png" class="img-responsive" /></td>
<td class="application-User-inv">Portal</td>
<td>User</td>
<td>Pending Approval</td>
</tr>
<tr>
<td class="application-User-inv"><img src="../images/delete_1.png" class="img-responsive" /></td>
<td class="application-User-inv">SSR</td>
<td>User</td>
<td>Provisioned</td>
</tr>
</tbody>
</table>
</div>
</td>
<td></td>
<td>
</td>
<td></td>
</tr>
<tr class="clickable apply-max-width">
<td class="table-tr1-td1 togglebutton"><b aria-hidden="true" data-toggle="collapse" data-target="#accordion2"><img src="../images/plus.png"/></b></td>
<td>[email protected]</td>
<td colspan="2">WD100165</td>
<td>2/1/2017</td>
<td>YES</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td colspan="2">
<div id="accordion2" class="accordion collapse data-found">
<table class="table table-striped data-table-inner-disabled div-found">
<thead>
<tr>
<th></th>
<th class="">Application</th>
<th class="">App Role</th>
<th>Workflow Status</th>
</tr>
</thead>
<tbody>
<tr>
<td class="application-User-inv"><img src="../images/delete_1.png" class="img-responsive" /></td>
<td class="application-User-inv">Portal</td>
<td>User</td>
<td>Pending Approval</td>
</tr>
<tr>
<td class="application-User-inv"><img src="../images/delete_1.png" class="img-responsive" /></td>
<td class="application-User-inv">SSR</td>
<td>User</td>
<td>Provisioned</td>
</tr>
</tbody>
</table>
</div>
</td>
<td></td>
<td>
</td>
<td></td>
</tr>
答
您需要存储船旗国每个手风琴。一个简单的方法做,这是使用jQuery数据()...
$('.togglebutton').data("flag",1);
$('.togglebutton').click(function() {
var $t = $(this);
if ($t.data("flag") == 1) {
$t.find('img')[0].src = "//placehold.it/40/?text=M";
$t.data("flag",0);
} else {
$t.find('img')[0].src = "//placehold.it/40/?text=P";
$t.data("flag",1);
}
})
这是不完美的工作对我来说..有,我需要用我的HTML代码做任何改变?什么是“//placehold.it/40/?text=M? –
我不知道为什么它不适合你,这些只是其他占位符图像,因为你没有提供正负图像的实际链接。澄清什么是不工作 – ZimSystem
现在它的工作..这是我自己的错..感谢吨 –