[英]How can I insert AJAX output before a target and then hide it?
我试图弄清楚如何隐藏目标元素之前插入的某些输出。 我正在这样做,以便以后可以为其设置动画。
到目前为止,这是我所做的-但是在将输出插入目标之前,它无法隐藏输出!
$.ajax({
type: "POST",
url: ajaxURLvalue,
data: dataString,
cache: false,
success: function(html){
if(SetIn=='before') {
$('.'+followFrom+followFrom2).hide().before(html);
} else if(SetIn=='prepend') {
$('.'+followFrom+followFrom2).hide().prepend(html);
} else if(SetIn=='append') {
$('.'+followFrom+followFrom2).hide().append(html);
} else if(SetIn=='after') {
$('.'+followFrom+followFrom2).hide().after(html);
} else if(SetIn=='prependto') {
$('.'+followFrom+followFrom2).hide().prependTo(html);
}
}
});
现在,您要隐藏目标元素,然后在其之前插入一些内容。 大概您想做的就是在目标之前插入一些内容,然后隐藏所插入的内容 。
实现此目的的直接方法是从要插入的内容开始:
$(html)
...然后在目标之前插入:
$(html).insertBefore('.'+followFrom+followFrom2)
...然后将其隐藏:
$(html).insertBefore('.'+followFrom+followFrom2).hide();
为保持一致,您可能希望对所有内容使用相同的格式:
if(SetIn=='before') {
$(html).insertBefore('.'+followFrom+followFrom2).hide();
} else if(SetIn=='prepend') {
$(html).prependTo('.'+followFrom+followFrom2).hide();
} else if(SetIn=='append') {
$(html).appendTo('.'+followFrom+followFrom2).hide();
} else if(SetIn=='after') {
$(html).insertAfter('.'+followFrom+followFrom2).hide();
} else if(SetIn=='prependto') {
// this one doesn't make any sense - prepending the target
// to the new elements will remove it from the document entirely!
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.