bind('resize')与.resize()之间的jquery区别

dja*_*ngo 5 jquery

  1. $(window).bind('resize')和之间有什么区别$(window).resize()
  2. 我看到bind嵌套的地方resize.它有什么影响?见下面的代码.
  3. 我知道.resize()关于元素和窗口的工作.是否也bind以类似的方式工作......喜欢$('#el').bind('resize', function (event) { // stuff });

JS:

$(window).bind('resize', function (event) {
    $(window).resize(function () {
         // do something here
    });
});
Run Code Online (Sandbox Code Playgroud)

Ale*_*rt. 3

jQuery页面.resize()

此方法是 .on('resize', handler) 的快捷方式。

并且.on()是:

.on() 方法将事件处理程序附加到 jQuery 对象中当前选定的元素集。从 jQuery 1.7 开始,.on() 方法提供了附加事件处理程序所需的所有功能。有关从旧版 jQuery 事件方法进行转换的帮助,请参阅 .bind()、.delegate() 和 .live()。

所以基于 jQuery api 描述,我认为没有什么区别,它只是一个类似于$.click()和其他的快捷方式