$('.products ul-li').length在我注入照片之前输出0,在照片出现时输出5,但当我
$('.photos ul li').length outputs 0 before i inject the photos and outputs five when they appear but when i remove them it still shows 5
当我点击removePhotos按钮时,它将输出照片li长度。最初,当DOM加载它们时没有照片,所以它会输出0,当我单击显示照片时,我使用ajax注入我的照片。在我插入我的照片并单击removePhotos按钮后,它输出5,这是我拥有的照片数量,但问题是当我删除照片并单击removePhotos按钮时,它仍然输出5,而它应该输出0。关于如何解决这个问题有什么建议吗?
我的html
<div id="paris">
<h1>CRAPPY CHEESE</h1>
<button>Get Paris Photos</button>
<span>Remove Photos</span>
<ul class="photos">
</ul>
</div>
我的javascript
function Tour(el) {
var tour = this;
this.el = el;
this.hidePhotos = function() {
alert($('.photos ul li').length);
$('.photos').fadeOut();
}
this.fetchPhotos = function() {
$.ajax('photos.html', {
data: {location: $("#tour").data(this.el)},
success: function(response) {
this.el.find('.photos').html(response).fadeIn();
},
context: tour,
error: function() {
this.el.find('.photos').html('<li>There was a problem fetching the latest photos. Please try again.</li>');
},
timeout: 3000,
beforeSend: function() {
this.el.addClass('is-fetching');
},
complete: function() {
this.el.removeClass('is-fetching');
}
});
};
var kirt = this.el.on('click.showPhotos', 'button', this.fetchPhotos);
var pooh = this.el.on('click.removePhotos', 'span', this.hidePhotos);
}
$(document).ready(function() {
var paris = new Tour($('#paris'));
});
将回调传递到jQuery fadeOut函数中,该函数执行$(this).remove()
你的问题是,fadeOut只是隐藏了你的照片,但它们仍然存在于DOM中。
相关文章:
- 漂亮照片图片库中的Facebook赞按钮
- 图片照片库
- 在JavaScript中输出转义字符
- 如何在jQuery中将函数的输出分配给变量
- Javascript,输出结果后页面不断刷新
- Datetime格式为Friendly Time.Moment JS输出错误
- 如何将angularjs中的javascript字符串输出为循环数组
- HTML5FileReader输出到D3.js图表
- console.log以外的Javascript输出函数
- Eloquent JavaScript递归示例如何终止为返回1,但仍然输出指数值
- PHP中的数组输出
- 以不同的顺序输出数据
- 使用Rivets.js输出类
- 在Chrome扩展内部输出Google API调用
- 如何为d3.js图表输出组织/嵌套数据
- 将IndexedDB中的数据拉入数组,并通过ReactJS输出
- 一个ajax循环有两个输出错误innerHTML
- 快速排序程序未正确输出
- 将照片从javascript发送到php
- $('.products ul-li').length在我注入照片之前输出0,在照片出现时输出5,但当我