未绑定事件添加点击返回
当我运行以下代码时,我只希望 #overlay、#image + theNumber 和 #close 处于活动状态,因此我禁用 $('.box').click 但单击 #close 后我想重新启用点击 $('.box') 但到目前为止我还无法做到。我检查了其他答案,但无法将其放在一起。感谢您的帮助!
var handler = function() { var theIDval = $(this).attr('id'); var theNumber = theIDval.replace('box',''); $('.box').unbind('click'); $('#overlay').show(); $('#image' + theNumber).fadeIn(); $('#close').fadeIn(); $('#close').click( function () { $('#overlay').fadeOut(); $('#image' + theNumber).fadeOut(); $('#close').fadeOut(); }); }; $(document).ready( function() { $('.box').click(handler); });
When I run the following code, i only want the #overlay, #image + theNumber, and #close to be active so i am disabling $('.box').click but once #close is clicked i want to re-enable the click on $('.box') but I am unable to thus far. I've checked out other answers and wasn't able to put it together. Thanks for the help!!
var handler = function() { var theIDval = $(this).attr('id'); var theNumber = theIDval.replace('box',''); $('.box').unbind('click'); $('#overlay').show(); $('#image' + theNumber).fadeIn(); $('#close').fadeIn(); $('#close').click( function () { $('#overlay').fadeOut(); $('#image' + theNumber).fadeOut(); $('#close').fadeOut(); }); }; $(document).ready( function() { $('.box').click(handler); });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您所缺少的只是在
#close
点击处理函数http://jsfiddle.net/pxfunc/gUP68/
looks like all you're missing is re-binding the
.box
click event in your#close
click handler functionhttp://jsfiddle.net/pxfunc/gUP68/
如果我是你,我会这样做:
If I were you, I would do it like this: