gpt4 book ai didi

javascript - Jquery 切换效果不起作用

转载 作者:行者123 更新时间:2023-11-30 11:17:31 25 4
gpt4 key购买 nike

所以基本上我有一个 div,我想用它制作某种动画,首先我尝试切换 div,然后使用 .remove() jquery 函数从 DOM 中完全删除 div。但我现在遇到的问题是切换效果没有发生,它只是直接进入 remove() 代码。我试图延迟代码,但同样的事情发生了。有人可以帮助我理解为什么我的代码会这样吗?请运行下面的代码片段,您会发现没有切换效果。

function remv(){
$(".myDiv").toggle( "clip" );
$(".myDiv").remove();


alert('PORTUGAL IS GOIN TO WIN THE WORLD CUP AND CANT DO NOTHING ABOUT IT!');
document.getElementById("test").innerHTML="Portugal will be winner of the fifa world cup 2018";



}
.myDiv{
height:100px;
width:100px;
background-color: orange;

}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

</head>
<body>
<div class="container">
<center><h3><p id="test">Click on the surprise box</p></h3></center>
<center>

<div class="myDiv" onclick="remv()"></div><br>
</center>
</div>

</body>
</html>

最佳答案

这个呢?

function remv() {
$(".myDiv").toggle(
"clip",
function() {
$(".myDiv").remove();

alert('PORTUGAL IS GOIN TO WIN THE WORLD CUP AND CANT DO NOTHING ABOUT IT!');
document.getElementById("test").innerHTML="Winner of the fifa world cup 2018";
$( "#dialog" ).dialog();
}
);
}
.myDiv{
height:100px;
width:100px;
background-color: orange;

}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

</head>
<body>
<div class="container">
<center><h3><p id="test">Click on the surprise box</p></h3></center>
<center>
<div id="dialog" >

<img src="https://i.gifer.com/JgI9.gif" alt="Placeholder Image" />

</div>
<div class="myDiv" onclick="remv()"></div><br>
</center>
</div>
<script>
$( "#dialog" ).hide();
</script>
</body>
</html>

关于javascript - Jquery 切换效果不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51013949/

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