简体   繁体   English

单击加载更多按钮将图像附加到html页面

[英]append images to html page on click on load more button

Dynamic HTML page with PHP that has 12 images in first load and theres load more button to load another 12 image on click event, 带有PHP的动态HTML页面,该页面首次加载有12个图像,并在按钮事件中加载了更多按钮以加载另外12个图像,

Now the idea of this code to reduce page load time, So every things is going well but i have event onclick for each image loaded in this html page now how i can append new 12 images over the first 12 and so on and keep the event foreach image still running 现在,此代码的想法是减少页面加载时间,所以一切进展顺利,但是我在此html页面中加载的每个图像都有事件onclick,现在我如何在前12个图像上追加新的12个图像,依此类推并保持该事件foreach映像仍在运行

here's the code i use , 这是我使用的代码,

php to get first 12 images PHP获取前12张图片

$results_per_page = 12;
$page = 1;
$start = ($page-1)*12;
$data['styles'] = $this->Discover_model->get_more_styles($start); 

html handling images as html处理图像为

<div class="product-list grid column3-4-wrap" id="interiors_samples" >
                        <?php if($styles):?>
                        <?php foreach ($styles as $style) {?>
                        <div class="img_card col">
                                    <div class="sampleFind">
                                        <img class = "Int_img"  id="<?php echo $style->id?>" src="<?php echo base_url();?>include/int_imgs/ <?php echo $style->img_name;?>" alt="product-image">
                                    </div>
                        </div>
                        <?php }?>
                        <?php endif;?>
                            </div>

jquery function to load more images over firs image jQuery函数在冷杉图像上加载更多图像

$('#load').click(function(){
var click_time = 0;
                 if(click_time === 0){
                     var page = 2;
                    }
                 click_time++;

                 $.ajax({
                    type:'POST',
                    data:{pagenum:page},
                   url:'<?php  echo base_url(); ?>Process/getInterImgs',
                    success:function(data) {
                        $('#interiors_samples').append(data);
                        page = page + 1;
                         }
                });

        });

And this function get another 12 of images and return result to post call above 并且此函数获取另外12张图像并将结果返回到上面的post调用

public function getInterImgs() {

        $page = $_POST['pagenum'];
        $this->load->model('Discover_model');
        $results_per_page = 12;
        $start = ($page-1)*$results_per_page;
        $data['styles'] = $this->Discover_model->get_more_styles($start);

        $styles = $data['styles'];
        foreach ($styles as $style ){

            $loadimgs = '<div class="img_card col">
                                    <div class="sampleFind">
                                        <img class = "Int_img"  id="'.$style->id.'" src="'.base_url().'include/int_imgs/ '.$style->img_name.'" alt="product-image">
                                    </div>
                        </div>';
        }
        print_r($loadimgs);exit();
        return  $loadimgs;
    }

Now i need to know what is happened after append images to html Dom because the jquery method for each image works fine for first 12 images and doesn't work for loaded image known the id's name is the same with first 12 item 现在,我需要知道将图像追加到html Dom之后会发生什么,因为每个图像的jquery方法对于前12个图像都适用,并且不适用于已加载的图像,已知ID的名称与前12个项目相同

Any help please 任何帮助请

Try this : 尝试这个 :

$(document).on("click", "#load", function () {
    // your code
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM