[英]Having trouble debugging this jquery
好的,代碼應該像這個小提琴http://jsfiddle.net/mjmitche/6nar4/一樣工作,其中左側的任何盒子都可以放入黑盒子內的盒子中。
在我的實時網站上,它不起作用。 如果您將 go 發送到此 web 地址,然后等待大約 10 秒鍾,將出現一個下拉菜單,旁邊有一個“確認”按鈕。 單擊確認,它將打開一個新頁面。 新頁面右側的四個框都是可拖拽的,白框中的四個小框都是可拖放的。 然而,實際上,只有紅色的小框——在下面的代碼中是“#chair2”——是可丟棄的。 #chair1、#chair2、#chair3 不接受丟棄。
這是設置 droppable 和 draggable 的代碼部分
$(document).ready(function($) {
$("#cloud1, #cloud2, #cloud3, #cloud4").draggable();
$("#chair1, #chair2, #chair3, #chair4").droppable({
accept: "#cloud1, #cloud2, #cloud3, #cloud4",
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function (event, ui) {
$(this)
.addClass ("ui-state-highlight")
.find ("p")
.html("dropped");
$("#topnav4").css({'background':'pink'});
}
});
});
這是從頭到尾的所有 jquery 代碼
$(document).ready(function(){
$(init);
});
function init() {
cloudshow();
}
function cloudshow() {
$("#intro").fadeIn(1000, function(){
$("#intro2").fadeIn(1000, function(){
$("#cloud1").fadeIn(2000, function(){
$("#cloud2, #cloud5").fadeIn(2000, function(){
$("#cloud3, #cloud4, #cloud6").fadeIn(2000, function(){
$("#message").fadeIn(1000, function() {
$("#contactform").fadeIn(1000)
});
});
});
});
});
});
};
var img1 = "url('/wp-content/themes/thesis_18/custom/images/map.jpg') repeat";
$(".submit").click(function(){
$("body.custom").css({background: img1});
$("#topnav4, #cloud1, #cloud2, #cloud3, #cloud4, #cloud5, #cloud6, #intro, #intro2, #message, #contactform").fadeOut(1000, function (){
$("#sidenav").fadeIn(1000, function(){
$("#topnav4").css({'background': 'none', 'display':'block'});
$("#bigbox").fadeIn(1000, function(){
$("#cloud1").css({'display':'block', 'position':'absolute','left':'600px', 'top': '50px', 'z-index': '2'});
$("#cloud2").css({'display':'block', 'position':'absolute','left':'600px', 'top': '150px', 'z-index': '2'});
$("#cloud3").css({'display':'block', 'position':'absolute','left':'600px', 'top': '250px', 'z-index': '2'});
$("#cloud4").css({'display':'block', 'position':'absolute','left':'600px', 'top': '350px', 'z-index': '2'});
});
});
});
});
$(document).ready(function($) {
$("#cloud1, #cloud2, #cloud3, #cloud4").draggable();
$("#chair1, #chair2, #chair3, #chair4").droppable({
accept: "#cloud1, #cloud2, #cloud3, #cloud4",
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function (event, ui) {
$(this)
.addClass ("ui-state-highlight")
.find ("p")
.html("dropped");
$("#topnav4").css({'background':'pink'});
}
});
});
您在頁面上包含三次 jQuery。 在 Firebug 控制台中,如果您鍵入 jQuery.fn.draggable,您將得到未定義。 似乎多次包含 jQuery 會導致此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.