去评论
推扬网

木梼杌:jQuery中的bind()函数跟on()函数有什么区别呢?

admin
2020/08/12 13:39:18

杨媚的回答:

摘抄jQuery官方的bind()和on()方法各自的区别介绍如下:1、在on()方法介绍的与bind()方法的区别: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(). To remove events bound with .on(), see .off(). To attach an event that runs only once and then removes itself, see .one()2、在bind()方法介绍的与on()方法的区别:As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements.总结整理上述两段英文的区别意思为:bind()函数是jQuery 1.7之前或更早版本采用的一个用来绑定事件处理程序的函数;on()函数是jQuery 1.7版本提供的首选的用来绑定事件处理程序的函数;从1.7版本的介绍以及参数描述来看,其实这两个函数基本上用法一致,但可能在早期的版本中,bind()函数一次只能为标签对象绑定一个事件的处理程序,而on()函数则可以一次为多个不同的事件绑定处理程序。

廖家鑫的回答:

摘抄jQuery官方的bind()和on()方法各自的区别介绍如下:1、在on()方法介绍的与bind()方法的区别: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(). To remove events bound with .on(), see .off(). To attach an event that runs only once and then removes itself, see .one()2、在bind()方法介绍的与on()方法的区别:As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements.总结整理上述两段英文的区别意思为:bind()函数是jQuery 1.7之前或更早版本采用的一个用来绑定事件处理程序的函数;on()函数是jQuery 1.7版本提供的首选的用来绑定事件处理程序的函数;从1.7版本的介绍以及参数描述来看,其实这两个函数基本上用法一致,但可能在早期的版本中,bind()函数一次只能为标签对象绑定一个事件的处理程序,而on()函数则可以一次为多个不同的事件绑定处理程序。

陈亮亮的回答:

bind()函数可以对同一个对象进行多次事件绑定,bind函数其实就是对on函数进行了处理,如果单纯用on函数来绑定事件的话,那么之前绑定的时间将会被后面的覆盖掉,也就是说,你用on函数给某一个对象绑定了事件1和事件2,但是只有事件2才能被正确执行,事件1则被事件2覆盖掉了。而用bind函数则可以避免这个问题,它可以判断是否已经绑定了其他事件,并且不会将之前绑定的函数覆盖掉,而且如果之前绑定了一个和现在将要绑定的一摸一样的函数的话,这里将不在进行绑定。所以bind是比较强大的。其实bind也是对on函数进行的加工处理得到的。希望采纳