我正在开发一个javascript函数,该函数打开一个jquery模式窗口并进行ajax调用来填充该模式。我已经包含了'left‘和'right’div I-点击一个可以改变模式窗口的内容(滚动浏览照片幻灯片)。
一切都很好,除了一件事:如果我打开模式,然后关闭它,第二次打开它会导致这些“左/右”按钮将每次点击计入两次(点击“右”一次,但移动两个图像)。如果我关闭窗口并重新打开它,计数再次增加1(单击1次更改3次)。
解决这个问题的唯一方法是在模式窗口关闭时重新加载页面--但是有人知道更好的解决方案吗?基本上,我想“重置”模式窗口,但不想破坏它--我希望能够多次打开/关闭模式窗口,并让这些右/左按钮工作。
下面是我用来创建这些按钮的函数的一部分--谢谢你的建议/想法。
function getNextImage(direction) {
if(direction == 1) {
if(imageNumber == 1) {
imageNumber = lastImage;
} else {
--imageNumber;
}
}
if(direction == 2) {
if(imageNumber == lastImage) {
imageNumber = 1;
} else {
++imageNumber;
}
}
if(direction == 0) {
imageNumber = 1;
}
$.ajax({
type: "GET",
url: "phpIncludes/next_fetch.php",
cache: false,
data: {img : imageNumber, cap : imageNumber, width : dWidth, height : dHeight, a : album},
success: function(htmlpic) {
$("#left"+album).html(htmlpic);
}
});
}
$("#moveLeft"+album).click(function() {
getNextImage(1);
console.log("Image Number is: " + imageNumber);
});
$("#moveRight"+album).click(function() {
getNextImage(2)
console.log("Image Number is: " + imageNumber);
});发布于 2014-04-24 05:58:59
在此部分中:
$.ajax({ type:"GET",url:"phpIncludes/next_fetch.php",cache: false,data:{img : imageNumber,cap : imageNumber,width : dWidth,height : dHeight,a: album},success: function(htmlpic) { $("#left"+album).html(htmlpic);} });
在你将htmlpic添加到#left之前,proib首先放入empty this content #left并验证它是否完成了!!
https://stackoverflow.com/questions/23254990
复制相似问题