动态画廊

时间:2016-07-08 14:15:24

标签: javascript php jquery

您如何在jQuery中编写以下代码?

我的代码在php中运行,它创建了一种添加带有灯箱和图像的列表项的方法。没有写每个img src和lightbox链接。

<?php

                        $images = range(1, 3);

                        $rowCount = 0;

                        foreach ($images as $image) {
                        // stripping stuff:
                        echo '<li class="search-dogs"';


                          echo '><a href="images/gallery/search-dogs/'.$image.'.jpg" rel="lightbox[gallery]">
                              <img src="images/gallery/search-dogs/'.$image.'.jpg">
                            </a></li>';
                        }

       ?>

1 个答案:

答案 0 :(得分:1)

 var images = [1,2,3];
 var rowCount = 0;
 var TargetElement = 'body'; //html tag, .classTag, #htmlElementId
 for(var image in images) {
     // stripping stuff:
      $(TargetElement).append('<li class="search-dogs"><a href="images/gallery/search-dogs/'+image+'.jpg" rel="lightbox[gallery]"><img src="images/gallery/search-dogs/'+image+'.jpg"></a></li>');
 }