在进行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;
}
});
});
});//]]>
答案 0 :(得分:1)
您不需要$(窗口).load(函数()如您的问题中所述使用jQuery DOM ready事件来连接事件。通常当您收到http响应并再次加载页面时,您将只会松动只有在使用部分渲染时才会显示这些DOM事件。
如果您将 UPDATE PANELs 用作AJAX调用,那么这是一个常见问题,您需要确保在updatepanel活动结束后立即重新连接您的jQuery事件。 See this link
答案 1 :(得分:0)
此重复问题的解决方案可能是found here 这个解决方案和我一起工作。
作为结论,请从
更改您的代码$(function(){
$(".cmdclose").click(function(){
// your code
});
});
到
$(function(){
$(document).on("click",".cmdclose",function(){
//your code
});
});