Jquery load方法不适用于异步加载到div映像中
我正在尝试将图像从img文件夹加载到div scrollerContent中,但无法使其正常工作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');
//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');
});