Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery load方法不适用于异步加载到div映像中_Jquery_Asynchronous_Load - Fatal编程技术网

Jquery load方法不适用于异步加载到div映像中

Jquery load方法不适用于异步加载到div映像中,jquery,asynchronous,load,Jquery,Asynchronous,Load,我正在尝试将图像从img文件夹加载到div scrollerContent中,但无法使其正常工作 //Variables References var sections = $(".nav a"), pageBody = $("#scrollerContent"), next = $('.next'), prev = $('.prev'), img = $('img');

我正在尝试将图像从img文件夹加载到div scrollerContent中,但无法使其正常工作

//Variables References
        var sections = $(".nav a"),
            pageBody = $("#scrollerContent"),
            next = $('.next'),
            prev = $('.prev'),
            img = $('img');

        //Manage loading of pages
        sections.on('click', function(){
            pageBody.load("img/" + this.id + ".jpg");
            sections.removeClass('selected');
            $(this).addClass('selected');

对于任何有类似问题的人,下面的代码对我有效

//Variables References
    var sections = $(".nav a"),
        next = $('.next'),
        prev = $('.prev'),
        img = $('img'),
        largeImg = $('img.large');

    //Manage loading of pages
    sections.on('click', function(){
        largeImg.attr('src',"img/" + this.id + ".jpg"); 
        sections.removeClass('selected');
        $(this).addClass('selected');
利用

在服务器上,给定

html

i、 例如,at/img/images.html

js

JSFIDLE

<img id="image1" src="/img/path/to/image" />
<a href="#" class="image1">click</a>
    var sections = $(".nav a"),
        pageBody = $("#scrollerContent"),
        next = $('.next'),
        prev = $('.prev'),
        img = $('img');

    //Manage loading of pages
    sections.on('click', function(e){
      e.preventDefault(); 
      pageBody.load("/img/images.html #" + $(e.target).attr("class"));
        sections.removeClass('selected');
        // is `$(this)` here intended for `<img>` , or `sections` ?
        $(this).addClass('selected');
    });