如何在加载/添加新帖子到提要列表时隐藏帖子元素
how to hide a post element when loading/adding new post to feed list?
我在document.ready下有几个jquery函数,我使用on((方法将这些函数冒泡到"加载更多"按钮以及将新帖子添加到提要列表时。
尽管如此,我在加载新帖子时无法隐藏帖子页脚。它在首次加载页面(通过document.ready(时有效,但不适用于新帖子。我已经直接通过CSS尝试过,它可以工作,我添加了一个新帖子。但是,当我单击文本区域字段(这将触发页脚显示(时,它不起作用。
你有什么建议?有没有办法使用 ON(( 方法?
JS代码
$(document).ready(function(){
$(".footer").hide();
$(".comments-feed").hide();
$('ol.list-feed').on('click', '.small-textarea-main-feed', function () {
$(this).addClass("set-large");
//$(this).("footer-post").show();
$(this).next().find('button#cenas').prop('disabled', $(this).val() == '');
$(this).next('div.footer').slideDown("fast");
$(this).next('.comments-feed').slideToggle('200');
});
$('ol.list-feed').on('keyup', '.set-large', function () {
$(this).next().find('button#cenas').prop('disabled', $(this).val() == '');
});
$('ol.list-feed').on('focusout', '.small-textarea-main-feed', function(){
if ($(this).val() !== '') {
}
else {
$(this).removeClass("set-large");
$(this).siblings('div.footer').hide();
$(".comments-feed").hide();
}
});
$('ol.list-feed').on('click', 'button#cancel', function () {
$(this).parents('.footer').hide();
$(this).parents('.footer').siblings('.small-textarea-main-feed').removeClass('set-large');
$(this).parents('.footer').siblings('.small-textarea-main-feed').val('');
});
});
帖子的 HTML 部分
当我第一次加载页面(document.ready(时,它用(.footer(.hide((做我想做的事情。但是,当我添加一个帖子(有一个表单 - 非常简单(时,它会将帖子加载到提要中,并且不会隐藏帖子页脚(下面的代码(。正如我所说,我试图通过使用"display:none"来更改页脚样式,尽管它会影响所有帖子。
<div id="" class="footer-condensed">
<textarea class="small-textarea-main-feed" type="text" placeholder="Reply to @Gerardo"></textarea>
<div id="" class="footer-post">
<div id="" class="footer-submit-button" style:"display:none;">
<button type="button" id="cancel" class="btn" onclick="cancel_button();" >Cancel</button>
<span id="footer-btn-margin"></span>
<button type="button" id="hunch" class="btn btn-info">Hunch</button>
</div>
</div>
</div>
JS用于加载帖子(是的,我尝试在此处使用hide((方法但不起作用 - 它在评论中(
$('form.cenas').submit(function() {
//
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
//event.preventDefault();
$.ajax({
url: url,
type: type,
data: data,
cache: false, // it will force requested pages not to be cached by the browse
success: function(html){
console.log(html);
$("ol#list-feed").prepend(html);
$("ol#list-feed li:first").slideDown(600);
//$("ol#list-feed > li.footer").hide();
//$("li.comments-feed").hide();
document.getElementById('set-width1').value='';
document.getElementById('tags').value='';
if ($("ol#list-feed > li").size() <= 3) {
$('#loadmorebutton').hide();
} else {
$("ol#list-feed > li:last").remove();
$('#loadmorebutton').show();
}
}
});
//event.preventDefault();
return false;
});
我仍然不完全确定我是否理解您的页面结构,但我认为如下:
- 您有一个帖子列表,每个帖子都包含一个页脚 (.footer(。
- 这些页脚在页面加载时全部隐藏($(".footer"(.hide((;)
- 您还有一个用于添加新帖子的表单,并且您希望新添加的帖子在隐藏页脚的情况下显示。
如果上述内容正确,您应该能够通过更新成功处理程序来修复它,如下所示:
success: function(html){
console.log(html);
//Create a jquery object from the returned html
var newPost = $(html);
//Hide the footer in the new post.
$('.footer', newPost).hide();
//Add the new post
$("ol#list-feed").prepend(newPost);
$("ol#list-feed li:first").slideDown(600);
//$("ol#list-feed > li.footer").hide();
//$("li.comments-feed").hide();
document.getElementById('set-width1').value='';
document.getElementById('tags').value='';
if ($("ol#list-feed > li").size() <= 3) {
$('#loadmorebutton').hide();
} else {
$("ol#list-feed > li:last").remove();
$('#loadmorebutton').show();
}
}
相关文章:
- 如何使用javascript将值引导下拉列表设置为隐藏值asp.net
- 当链接单击-jQuery时,第二层下拉列表将隐藏
- 修复列表的绝对位置(li's隐藏在前两个后面)
- 如何使用jQuery隐藏与选择选项相关的选择选项列表
- 使用2个下拉列表显示/隐藏分区
- 选中复选框时如何显示/隐藏下拉列表
- 如何在 *ngFor 列表中显示单击的元素,使用 Angular 2 隐藏其他元素
- 从未隐藏的列表项中获取项
- HTML 表单字段根据从下拉列表中选择的选项显示/隐藏
- 根据下拉列表中选择的项目隐藏所有元素
- 隐藏并显示列表中的元素
- 删除或隐藏下拉列表中的一些值,该列表由使用JavaScript的存储过程填充
- 如何使用jQuery显示()和隐藏()列表项块
- 如何从另一个下拉列表中隐藏选择基于下拉列表的值
- 如何部分隐藏asp.net复选框列表项
- 以父对象为中心并带有溢出的下拉列表:隐藏
- 引导程序选择下拉列表被另一个下拉列表隐藏
- 动态列表隐藏空元素
- 如何根据另一个下拉列表隐藏和显示下拉列表值
- 如何使嵌套列表隐藏类似于jquery移动.示例包括在内