jquery:取消绑定加载的函数
我有一个函数,可以在加载页面时调整图像背景的大小,
$(document).ready(function(){
loadBackground();
});
并且我想在单击按钮时“卸载”或“删除”此加载的函数,以便我可以重新加载此函数,而不是将其加载到顶部页面的,
$('.get-image').click(function(){
$(window).unbind("resize",loadBackground);
loadBackground();
return false;
});
但我无法使它工作!有什么想法吗?
谢谢, 刘
I have a function which will resize the image background when the page is loaded,
$(document).ready(function(){
loadBackground();
});
and I want to 'unload' or 'remove' this loaded function when I click on a button so that I can load this function anew instead of loading it on top of the page,
$('.get-image').click(function(){
$(window).unbind("resize",loadBackground);
loadBackground();
return false;
});
but I can't make it work! any ideas please?
thanks,
Lau
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的评论,我认为您根本不需要取消绑定:
您首先要在加载页面时加载背景,然后在单击发生时加载背景。
调整图像大小时背景会发生什么应该是绑定到
$(window).resize()
的另一个单独的函数...所以整个事情看起来像这样:($(function() { ... });
与$(document).ready(function() { ... })
含义相同,只是写起来更快:Based on your comments, I don't think you need to unbind at all:
You first want to load the background when the page is loaded, and then you want to load the background when a click happens.
What happens to the background when the image is resized should be another separate function that is bound to
$(window).resize()
... so the whole thing will look like this:(
$(function() { ... });
means the same as$(document).ready(function() { ... })
it's just faster to write: