dongzhiqi0332 2015-01-29 15:49
浏览 88
已采纳

HTML5 div包装克隆

How can i clone the below HTML5 wrap. The code contains also some php serialized that must be in order , example Article one has <?php echo $price[n];?> where n must be a number from 0-15.

<!-- ARTICLE START -->
    <div class="col-sm-6 col-md-4">
        <article class="box has-discount">
            <figure>
                <a class="hover-effect popup-gallery" href=
                "ajax/slideshow-popup.html"><img alt="" height="161" src=
                "<php echo $img[0];?>" width="270"></a> <span class=
                "discount"><span class="discount-text">VIP
                DISCOUNT</span></span>
            </figure>

            <div class="details">
                <span class="price"><small>avg/night</small> $<php echo $price[0];?></span>

                <h4 class="box-title"><php echo $name[0];?>small><php echo $city[0];?></small></h4>

                <div class="feedback">
                    <div class="five-stars-container" data-original-title=
                    "4 stars" data-placement="bottom" data-toggle="tooltip"
                    title="">
                        <span class="five-stars" style="width: 80%;"></span>
                    </div><span class="review">270 reviews</span>
                </div>

                <p class="description">Nunc cursus libero purus ac congue arcu
                cursus ut sed vitae pulvinar massa idporta nequetiam.</p>

                <div class="action">
                    <a class="button btn-small" href=
                    "hotel-detailed.html">SELECT</a> <a class=
                    "button btn-small yellow popup-map" data-box=
                    "48.856614, 2.352222" href="#">VIEW ON MAP</a>
                </div>
            </div>
        </article>
    </div>
<!--  ARTICLE END -->

I have a code that generates arround 20-30 hotels, Each hotel has his own article and his own variable as $price[], $name[], etc were the [n] value in a number in ascending order starting from 0. How can i generate the above div x how many hotels availeble and to insert the variable value automatic ?.

  • 写回答

1条回答 默认 最新

  • droi5225 2015-01-29 16:03
    关注

    something like this? http://jsfiddle.net/swm53ran/173/

    i simplified the code a bit and did everything in jquery, but i put notes on how to do it with php (i dont have readily available access to php editor) but the concept is the same.

    <div class="hotel" id="template" style="display:none;">
        <div class="name"></div>
        <div class="price"></div>
    </div>
    
    
    $(document).ready(function() {
        var hotels = [
            {'name': 'hotel1', 'price':'$200'},
            {'name': 'hotel2', 'price':'$300'},
            {'name': 'hotel3', 'price':'$700'},
            {'name': 'hotel4', 'price':'$100'}
        ];
        for(var i = 0; i < hotels.length; i++) {
            var clone = $('#template').clone(true).attr('id', '');
            clone.css('display', '');
            clone.find('.name').html('Name: ' + hotels[i]['name'] + '. With php should be something like < ? php echo $name[i]; ? >');
            clone.find('.price').html('Price: ' + hotels[i]['price'] + '. With php should be something like < ? php echo $price[i]; ? >');
            clone.appendTo('body');
        }
    });
    

    you'd get the hotels array from php (im assuming) and then you can put php right into the html of the clone if you take out the spaces, then use i as the incrementor from the for loop. hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据