jQuery bind('resize')与.resize()之间的区别 [英] jquery difference between bind('resize') vs .resize()

查看:232
本文介绍了jQuery bind('resize')与.resize()之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. $(window).bind('resize')$(window).resize()有什么区别?
  2. 我看到了bind嵌套在resize上的某个地方.它有什么影响?参见下面的代码.
  3. 我知道.resize()适用于元素以及窗口. bind是否也以类似方式工作... 像$('#el').bind('resize', function (event) { // stuff });?
  1. What is the difference between $(window).bind('resize') and $(window).resize()?
  2. I saw somewhere bind nested over resize. What impact does it have? See code below.
  3. I know .resize() works on elements as well as window. Does bind 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆