gpt4 book ai didi

javascript - jquery fadeIn 函数作为回调函数,带有 $ ("this") 参数

转载 作者:行者123 更新时间:2023-11-28 06:28:16 25 4
gpt4 key购买 nike

我正在尝试执行一个简单的功能,以便元素会淡入然后淡出。这是我的代码:

function ShowBoxes() {
$("#divTestArea21").fadeIn("fast", function () {
FadeThisOut($(this));
});
$("#divTestArea22").fadeIn("slow");
$("#divTestArea23").fadeIn(2000);
}


function FadeThisOut(sender) {
sender.fadeOut("slow");
}
<!DOCTYPE html>
<html>
<head>
<title>jQuery test</title>
<script src="Scripts/jquery-2.2.0.js"></script>
<script type="text/javascript" src="Scripts/IndexScript.js"></script>
<link href="CSS/SiteStyle.css" rel="stylesheet" />


<meta charset="utf-8" />
</head>
<body>
<div id="divTestArea21" style="width: 50px; height: 50px; display: none; background-color: #89BC38;"></div>
<div id="divTestArea22" style="width: 50px; height: 50px; display: none; background-color: #C3D1DF;"></div>
<div id="divTestArea23" style="width: 50px; height: 50px; display: none; background-color: #9966FF;"></div>
<a href="javascript:void(0);" onclick="ShowBoxes();">Show boxes</a>


</body>
</html>

有人可以向我解释一下为什么它不起作用以及如何修复它吗?

编辑:你是对的,我有一个 FadeThisOut 函数的参数,但我玩了一会儿我的代码并尝试了其他东西,所以我忘记把它带回来。无论如何,我删除了双引号,现在它可以工作了。谢谢大家。

最佳答案

首先,您使用 $(this) 作为参数调用您的函数,但您没有声明它,首先这样写:

function FadeThisOut(object) {
}

其次,您使用 sender[0],但没有向我们展示什么是 sender 数组。

第三,在函数调用中,应该不带引号调用当前对象,即:$(this)

关于javascript - jquery fadeIn 函数作为回调函数,带有 $ ("this") 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34929656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com