Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.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
Javascript 如何在目标之前插入AJAX输出,然后将其隐藏?_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 如何在目标之前插入AJAX输出,然后将其隐藏?

Javascript 如何在目标之前插入AJAX输出,然后将其隐藏?,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我试图找出如何隐藏插入到目标元素之前的一些输出。我这样做是为了以后可以给它设置动画 这就是我到目前为止所做的-但是当输出插入到目标之前时,它无法隐藏输出 $.ajax({ type: "POST", url: ajaxURLvalue, data: dataString, cache: false, success: function(html){ if(SetIn=='before

我试图找出如何隐藏插入到目标元素之前的一些输出。我这样做是为了以后可以给它设置动画

这就是我到目前为止所做的-但是当输出插入到目标之前时,它无法隐藏输出

        $.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!
    }

需要更多信息。我不跟随。我要隐藏以下内容:$('.'+followFrom+followFrom2.Hide().before(html);正如您所看到的,代码中已经有了hide()。但它并没有隐藏它当Ajax运行时,如果我想让div可见的话,div就会按它应该的样子出现。但是我想把它隐藏起来如果你alert()$('.+followFrom+followFrom2),你得到一个HTML元素作为响应吗?是的,然后我得到:#inside#this4#ltl#u nextTo1-哪些是正确的?我在浏览器日志中得到这个错误:[错误]错误:语法错误,无法识别的表达式:2,1->sharedID,langID152error(jquery-2.0.3.min.js,第4行)gt(jquery-2.0.3.min.js,第4行)kt(jquery-2.0.3.min.js,第4行)ot(jquery-2.0.3.min.js,第4行)find(jquery-2.0.3.min.js,第5行)init(jquery-2.0.3.min.js,第4行)x(jquery-2.0.3.min.js,第4行)success(anonym funktion)(jquery-2.0.3.min.js,第6行)将在此处冒险猜测
html
并非完全有效的html。按照所述的每个步骤进行操作,查看错误出现的位置,然后检查输入。