簡體   English   中英

HTML img src附加

[英]HTML img src appending

我在php中有一個創建按鈕的循環,當單擊該按鈕時,將打開一個模態,並將某些數據傳遞給它。

<?php while($product = mysqli_fetch_assoc($featured)) :?>
<button type="button" class="open-details-modal btn btn-primary"
      data-id-number="<?php echo $product['ProductID'];?>
      "data-id-image="<?php echo $product['Image'];?>"
      "data-id-image-two="<?php echo $product['Image2'];?>"
      "data-id-image-three="<?php echo $product['Image3'];?>"

我有一個腳本可以幫助轉換數據

<script>
$(document).ready(function() {
  $(".open-details-modal").click(function() {
      $("#name").text($(this).attr('data-id-product-name'));
      $("#image").text($(this).attr('data-id-image'));
      $("#image2").text($(this).attr('data-id-image-two'));
      $("#image3").text($(this).attr('data-id-image-three'));

可以說

"data-id-image" = ABCDEF

我不確定是否需要將其轉換為javascript變量或php變量。

我想說的是

<img src = "(#php or javascript variable)" +"001.jpg">

我如何在php或javascript中實現此目的。

假設#image是您的圖像,則如下所示:

  $(".open-details-modal").click(function() {
      $("#name").text($(this).attr('data-id-product-name'));
      $("#image").text($(this).attr('data-id-image'));
      $("#image").attr("src", $(this).attr("data-id-image") + "001.jpg");
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM