带有图像显示的桌子

时间:2018-11-22 19:10:18

标签: jquery bootstrap-4

有人可以帮我吗,我需要创建一个表格,当我单击一行时更改旁边的显示图像。类似于下面显示的内容。

2 个答案:

答案 0 :(得分:0)

$("#rowid").click(function(){
    $("imageid").show();
}); 

答案 1 :(得分:0)

这是一个基本示例:

         

<div class="box-body">
    <div class="row">
        <div class="col-md-8">
            <div class="row pad">
                <div class="col-md-12">
                    <h3><i class="fa fa-table"></i> Produtcs Report</h3>
                </div>
            </div>
            <div class="box">
                <div class="box-body table-responsive">
                    <table class="table table-striped">
                       <thead>
                            <tr>
                                <th>Codigo</th>
                                <th>Descricao</th>
                                <th>Vlr. Unit.</th>
                                <th>Quantidade</th>
                                <th>Total</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr name="loadPhoto" data-url="https://picsum.photos/200/300/?image=1">
                                <td>123456789</td>
                                <td>DESCRICAO 1 BLA BLA BLA</td>
                                <td>41,99</td>
                                <td>1</td>
                                <td>41,99</td>
                            </tr>
                            <tr name="loadPhoto" data-url="https://i.stack.imgur.com/xljCS.png">
                                <td>123456789</td>
                                <td>DESCRICAO 2 BLA BLA BLA</td>
                                <td>41,99</td>
                                <td>1</td>
                                <td>41,99</td>
                            </tr>
                            <tr name="loadPhoto" data-url="https://picsum.photos/200/300/?image=2">
                                <td>123456789</td>
                                <td>DESCRICAO 3 BLA BLA BLA</td>
                                <td>41,99</td>
                                <td>1</td>
                                <td>41,99</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div>
                <img id="productImage" width="300" />
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $("tr[name='loadPhoto']").click(function(){
            url = $(this).data('url');
            $('#productImage').attr('src', url);
        });
    });
</script>