Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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 淡出,替换HTML和淡出_Javascript_Jquery - Fatal编程技术网

Javascript 淡出,替换HTML和淡出

Javascript 淡出,替换HTML和淡出,javascript,jquery,Javascript,Jquery,我在使用一个简单的JQuery函数时遇到了一些问题,该函数可以淡出一个元素,替换其中的图像,然后再次淡入 我的函数如下所示: function nextPage() { $("#leftPage").fadeOut("slow", function() { $("#leftPage").html="<img src='page4.jpg'>"; $("#leftPage").fadeIn("slow");

我在使用一个简单的JQuery函数时遇到了一些问题,该函数可以淡出一个元素,替换其中的图像,然后再次淡入

我的函数如下所示:

function nextPage() {
        $("#leftPage").fadeOut("slow", function() {
            $("#leftPage").html="<img src='page4.jpg'>";
            $("#leftPage").fadeIn("slow");
        });

        $("#rightPage").fadeOut("slow", function() {
            $("#rightPage").html="<img src='page5.jpg'>";
            $("#rightPage").fadeIn("slow");
        });
}
淡入/淡出部分工作正常,但HTML并没有被新图像取代。你能看出这有什么问题吗

function nextPage() {
    $("#leftPage").fadeOut("slow", function () {
        $("#leftPage").html("<img src='page4.jpg'>");
        $("#leftPage").fadeIn("slow");
    });
    $("#rightPage").fadeOut("slow", function () {
        $("#rightPage").html("<img src='page5.jpg'>");
        $("#rightPage").fadeIn("slow");
    });
}
您正在将一个字符串分配给.html,它实际上是一个将字符串作为参数的函数,而不是一个可以分配内容的属性

请注意,在上面的代码段中,我已将.html=更改为.html。现在,它将一个字符串传递给.html,后者相应地更新元素

您正在将一个字符串分配给.html,它实际上是一个将字符串作为参数的函数,而不是一个可以分配内容的属性

请注意,在上面的代码段中,我已将.html=更改为.html。现在,它将一个字符串传递给.html,该字符串相应地更新元素。

最重要的是:

试试这个:

function nextPage() {
        $("#leftPage").fadeOut("slow", function() {
            $("#leftPage").html("<img src='page4.jpg'>");
            $("#leftPage").fadeIn("slow");
        });

        $("#rightPage").fadeOut("slow", function() {
            $("#rightPage").html("<img src='page5.jpg'>");
            $("#rightPage").fadeIn("slow");
        });
}
jquery的html是一个函数,而不是一个属性。将要替换元素内容的html作为参数传入

尝试以下操作:

function nextPage() {
        $("#leftPage").fadeOut("slow", function() {
            $("#leftPage").html("<img src='page4.jpg'>");
            $("#leftPage").fadeIn("slow");
        });

        $("#rightPage").fadeOut("slow", function() {
            $("#rightPage").html("<img src='page5.jpg'>");
            $("#rightPage").fadeIn("slow");
        });
}
jquery的html是一个函数,而不是一个属性。将要替换元素内容的html作为参数传入,请尝试:

$("#leftPage").html("<img src='page4.jpg'>");
以及:

尝试:

以及:

您使用jQuery的.html错误

您使用jQuery的.html错误

$("#rightPage").html("<img src='page5.jpg'>");
function nextPage() {
    $("#leftPage").fadeOut("slow", function() {
        $("#leftPage").html("<img src='page4.jpg'>");
        $("#leftPage").fadeIn("slow");
    });

    $("#rightPage").fadeOut("slow", function() {
        $("#rightPage").html("<img src='page5.jpg'>");
        $("#rightPage").fadeIn("slow");
    });
}