亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

單擊圖像時,圖像列表中的相同圖像以模態顯示

單擊圖像時,圖像列表中的相同圖像以模態顯示

MM們 2022-01-20 18:47:20
我已經制作了用于在單擊圖像列表中的圖像時顯示大圖像的模式。但它在單擊任何圖像時同時顯示相同的圖像。目前我每次點擊圖片都會得到相同的圖片我想查看單擊圖像的不同圖像。我的代碼看起來像這樣while($row = mysqli_fetch_array($attachment)){    ?>    <tr id='ea<?php echo $row['enquiry_attachment_id'];?>'>        <th><?php             $ext = pathinfo($row['file_name'], PATHINFO_EXTENSION);            $allowed =  array('gif','png' ,'jpg','jpeg');            if(in_array(strtolower($ext),$allowed) ) {                echo "                <div class='pop'>                <image class='imageresource' id='imageresource'  src='assets/enq_attachment/".$row['file_name']."' style='width:100px;height:100px'>                </div>                ";            }else{                if($ext == "pdf"){                    echo "<i class='fa fa-file-pdf-o'></i>";                }else if($ext == "xls" || $ext == "xlsx" || $ext == "csv"){                    echo "<i class='fa fa-file-excel-o'></i>";                }else{                    echo $row['file_name'];                }            }        ?></th>        <td><a href="assets/enq_attachment/<?php echo $row['file_name'];?>" target='_blank'>DOWNLOAD</a></td>        <td><span class="btn btn-danger" onclick="deleteFun('enquiry_attachment',<?php echo $row['enquiry_attachment_id'];?>,'ea<?php echo $row['enquiry_attachment_id'];?>')"><i class="fa fa-times"></i> </span></td>    </tr>    <?php    $number = $number + 1;}模態看起來像這樣<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">  <div class="modal-dialog" role="document">    <div class="modal-content">      <div class="modal-header">        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>        <button type="button" class="close" data-dismiss="modal" aria-label="Close">          <span aria-hidden="true">&times;</span>        </button>      </div>
查看完整描述

2 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

就像我說我不使用 jQuery 但我認為基本上你的代碼發生的事情是事件偵聽器需要引用接收click事件的元素然后找到子節點?img.imageresource


順便我忘了說,標簽應該是img而不是image


 $(function() {

    $('.pop').on('click', function() {



        /* or should that be $( this ) ?? */


        let child=this.querySelector('img.imageresource')

        $('.imagepreview').attr( 'src', child.src );



        $('#imagemodal').modal('show');   

    });     

});


查看完整回答
反對 回復 2022-01-20
?
蠱毒傳說

TA貢獻1895條經驗 獲得超3個贊

如果您正在尋找基于純jquery的解決方案,那么您可以使用以下代碼


    $('.pop').on('click', function() {

        var imgSrc = $(this).children('.imageresource').attr('src'); //get image src here

        $('.imagepreview').attr('src', imgSrc );

        $('#imagemodal').modal('show');   

    });  


查看完整回答
反對 回復 2022-01-20
  • 2 回答
  • 0 關注
  • 207 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號