我想将访客将三个硬币拖到三个不同的罐子中后,将访客发送到新页面,但是我不确定将硬币拖入罐子后如何触发新页面。
我希望这样的事情会起作用:
http://jsfiddle.net/F8L44/
$(init);
function init() {
$('#makeMeDraggable1').draggable();
$('#makeMeDroppable1').droppable({
drop: function () {
$("#makeMeDraggable1").draggable("option", "containment", "#makeMeDroppable1");
}
});
$('#makeMeDraggable2').draggable();
$('#makeMeDroppable2').droppable({
drop: function () {
$("#makeMeDraggable2").draggable("option", "containment", "#makeMeDroppable2");
}
});
$('#makeMeDraggable3').draggable();
$('#makeMeDroppable3').droppable({
drop: function () {
$("#makeMeDraggable3").draggable("option", "containment", "#makeMeDroppable3");
}
});
}
最佳答案
$(init);
function init () {
var drops = 0,
redirectIfDone = function () {
if (drops === 3) {
window.location = 'http://www.google.com';
}
};
$('#makeMeDraggable1').draggable();
$('#makeMeDroppable1').droppable({
drop: function () {
drops++;
redirectIfDone();
$("#makeMeDraggable1").draggable("option", "containment", "#makeMeDroppable1");
}
});
$('#makeMeDraggable2').draggable();
$('#makeMeDroppable2').droppable({
drop: function () {
drops++;
redirectIfDone();
$("#makeMeDraggable2").draggable("option", "containment", "#makeMeDroppable2");
}
});
$('#makeMeDraggable3').draggable();
$('#makeMeDroppable3').droppable({
drop: function () {
drops++;
redirectIfDone();
$("#makeMeDraggable3").draggable("option", "containment", "#makeMeDroppable3");
}
});
}