在进行 AJAX 调用后,我遇到了 jQuery 无法正常工作的问题。这是一个可以正常工作的拖放脚本,但是当我想调用 AJAX 时它会停止。
var ary1=new Array(5);
ary1[0]="container1";
ary1[1]="container2";
ary1[2]="container3";
ary1[3]="container4";
ary1[4]="main_container";
var ary2=new Array(5)
ary2[0]=0;
ary2[1]=0;
ary2[2]=0;
ary2[3]=0;
ary2[4]=4;
var i;
var srouce,dest;
var old;
$(window).load(function(){
$(function() {
$( ".draggable" ).draggable();
$( ".droppable, #droppable-inner" ).droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function( event, ui ) {
//if(ui.draggable.parent().attr('id')=="container1")alert("Yep");
alert(ui.draggable.attr('id') + ' was dropped from ' + ui.draggable.parent().attr('id')+' into '+$(this).attr('id'));
$( this ).addClass( "ui-state-highlight" );
// Move the dragged element into its new container
srouce= ui.draggable.parent().attr('id');
dest=$(this).attr('id');
for(i=0;i<5;i++){
if(srouce==ary1[i])break;} // to get src
alert(ary1[i]);
if((ary2[i]>0&&ary2[i]<=4&&ary1[i]=="main_container")|| (ary2[i]==1&&ary1[i]!="main_container"))
{
old=i;
ary2[i]--;
alert(ary2[i]); // decrement flag
for(i=0;i<5;i++){
if(ary1[i]==dest)break;}//to get dest
alert(ary1[i]);
if((ary2[i]==0&&ary1[i]!="main_container")|| (ary2[i]>=0&&ary2[i]<4&&ary1[i]=="main_container"))
{
ary2[i]++;//increment flag
alert(ary2[i]);
ui.draggable.attr('style','position:relative ;cursor:hand');// move the image
$(this).append(ui.draggable);
}
else
{
ary2[old]++;
ui.draggable.attr('style','position:relative ;cursor:hand');
ui.draggable.parent().append(ui.draggable);
}
}
return false;
}
});
});
});//]]>