jQuery bind('resize')与.resize()之间的区别 [英] jquery difference between bind('resize') vs .resize()
问题描述
-
$(window).bind('resize')
和$(window).resize()
有什么区别? - 我看到了
bind
嵌套在resize
上的某个地方.它有什么影响?参见下面的代码. - 我知道
.resize()
适用于元素以及窗口.bind
是否也以类似方式工作... 像$('#el').bind('resize', function (event) { // stuff });
?
- What is the difference between
$(window).bind('resize')
and$(window).resize()
? - I saw somewhere
bind
nested overresize
. What impact does it have? See code below. - I know
.resize()
works on elements as well as window. Doesbind
work in similar way too... like$('#el').bind('resize', function (event) { // stuff });
?
JS:
$(window).bind('resize', function (event) {
$(window).resize(function () {
// do something here
});
});
推荐答案
来自 jQuery 页面
此方法是.on('resize',handler)的快捷方式.
This method is a shortcut for .on('resize', handler).
和.on()
是:
.on()方法将事件处理程序附加到当前选定的集合 jQuery对象中的元素的集合.从jQuery 1.7开始,.on()方法 提供附加事件处理程序所需的所有功能.为了 从旧版jQuery事件方法转换的帮助,请参见.bind(), .delegate()和.live().
The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the .on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind(), .delegate(), and .live().
因此,根据jQuery API描述,我认为这只是与$.click()
和其他类似的快捷方式
So based on jQuery api description, I think there is no difference it's just a shortcut similar to $.click()
and others
这篇关于jQuery bind('resize')与.resize()之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!