Bootstrap:Accordion Row:当有MULTIPLE ROWS时更改展开 - 折叠图标

时间:2017-05-09 11:21:58

标签: twitter-bootstrap icons accordion collapse expand

我有一张带有手风琴行的桌子。 我想在行展开 - 折叠时更改展开 - 折叠图标 我获得了一排成功。但是,当我尝试多行时,我的代码工作很糟糕,并与其他行冲突

如果有人有解决方案,请帮帮我

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>abcd@gmail.com</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>abcd@gmail.com</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>

1 个答案:

答案 0 :(得分:1)

您需要为每个手风琴存储标志状态。一种简单的方法是使用jQuery data()...

$('.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);
    }
})

http://codeply.com/go/e49vQb4wE4