gpt4 book ai didi

javascript - 如何在jQuery中找到所有被删除的元素

转载 作者:行者123 更新时间:2023-11-28 07:35:55 27 4
gpt4 key购买 nike

    .dropped
{
position: static !important;
}
#dvSource
{
padding: 5px;
min-height: 100px;
width: 470px;
margin-top: 300px;
}
#dvSource img {
padding-left: 10px;
}
.one {
left: 20px;
}
.nodrop {
padding-left: 20px;
}
#dvDest
{
background:url(images/line_background.png);
min-height: 100px;
width: 110px;
float: left;
margin-left: 20px;
}

#dvDest1
{
background:url(images/line_background.png);
display: inline-block;
min-height: 100px;
width: 110px;
margin-left: 10px;
}
#dvDest2
{
background:url(images/line_background.png);
display: inline-block;
min-height: 100px;
width: 110px;
margin-left: 10px;
}

#otherimgs {
float: left;

}
.allcontent {
width: 700px;
margin-top: 120px;
}
.contain {
text-align: center;

}
.contain img {
margin-left: 20px;

}
.popup {
position: absolute;
top: 280px;
right: 480px;
}
.popup img {
width: 435px;
height: 134px;

}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
function hideerror() {
$('.popup').remove();
}

$(function () {
$("#dvSource img.one").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});

$("#dvSource img.one1").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});
$("#dvSource img.one2").draggable({
revert: function () {
$(this).delay(600);
return true
},
revertDuration: 500,
refreshPositions: true,
stop: function (event, ui) {
$("body").append('<div class="popup"><img src="images/tryagain.png"></div>'); setTimeout(function(){hideerror()},1200);
}
});

$("#dvDest").droppable({
accept: '#dvSource img.one',
drop: function (event, ui) {
if ($("#dvDest img").length == 0) {
$("#dvDest").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
$( this ).hideerror();
}
});
$("#dvDest1").droppable({
accept: '#dvSource img.one1',
drop: function (event, ui) {
if ($("#dvDest1 img").length == 0) {
$("#dvDest1").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest1").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
$( this ).hideerror();
}
});
$("#dvDest2").droppable({
accept: '#dvSource img.one2',
drop: function (event, ui) {
if ($("#dvDest2 img").length == 0) {
$("#dvDest2").html("");
}
ui.draggable.addClass("dropped");
$("#dvDest2").append(ui.draggable);
$("body").append('<div class="popup"><img src="images/greatwork.png"></div>'); setTimeout(function(){hideerror()},1300);
setTimeout(function() {
window.location.href = "6.htm";
}, 1500);
$( this ).hideerror();
}
});

});
</script>
<div class="allcontent">
<div id="otherimgs">
<img alt="" src="images/large_ball.png" />
<img alt="" src="images/medium_ball.png" />
<img alt="" src="images/small_ball.png" />
</div>
<div class="contain">
<div id="dvDest"></div>
<div id="dvDest1"></div>
<div id="dvDest2"></div>
</div>
</div>
<div id="dvSource">
<img class="one" alt="" src="images/large_ball.png" />
<img class="one1" alt="" src="images/medium_ball.png" />
<img class="one2" alt="" src="images/small_ball.png" />
</div>

这里我已经将 3 个元素设置为可放置到各自的目标位置..我想仅当所有 3 个元素都放置在其位置时才将页面重定向到另一个页面..如何查找该元素是否已放置..任何人都可以帮我解决这个问题?

检查这个 fiddle 的演示 http://jsfiddle.net/karthikchandran/stxzqskq/3/

最佳答案

Fiddle Demo试试这个

function checked()
{
var i = 0;
if($("#dvDest").children("img").hasClass("dropped"))
{
i++;
}
if($("#dvDest1").children("img").hasClass("dropped"))
{
i++;
}
if($("#dvDest2").children("img").hasClass("dropped"))
{
i++;
}
console.log(i);
if(i ==3)
{
window.location.href="http://google.com";
}
}

创建一个checked()函数并在每个可删除函数上调用它它将被重定向到给定的链接,如 fiddle 演示中所示,但在 fiddle 中它不会被重定向。

关于javascript - 如何在jQuery中找到所有被删除的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28600790/

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