gpt4 book ai didi

javascript - jQuery 事件处理程序方法 - 混合对

转载 作者:行者123 更新时间:2023-12-03 07:54:09 26 4
gpt4 key购买 nike

jQuery 事件方法成对出现 - on()off()live()die()bind()unbind()

我的问题是,我们可以混合配对吗?例如,使用 on() 附加事件并使用 unbind() 删除事件?

文档向我建议最好的做法是使用相应的方法,bind()unbind() http://api.jquery.com/unbind/ ,但它并没有明确表示不能混合它们。在我看来, live()/die() 可以与 on()/off() 互换,以及 bind()/unbind() 以及简写方法,例如 click()/change()

有人还可以解释一下事件是如何附加、引用和存储的吗?据我了解,jQuery 事件存储在数组中,可以通过 obj.event("name") 引用。 on()/off()bind()/unbind() 使用不同的数组吗?

最佳答案

您可以使用.unbind()来取消绑定(bind)使用.on()注册的事件,反之亦然。在这里查看:http://codepen.io/anon/pen/KVyZOL

但是使用 .on() 和 .off() 是绑定(bind)和取消绑定(bind)事件的首选方式:

Event handlers attached with .bind() can be removed with .unbind(). (As of jQuery 1.7, the .on() and .off() methods are preferred to attach and remove event handlers on elements.)

--

how events are attached, refference and stored?

jQuery 根据浏览器支持使用 addEventListener() 和 AttachEvent() 附加事件。 check jQuery source code

正如你所说的 jQuery 事件:

are stored in a array and can be reffrenced via obj.event("name").

关于javascript - jQuery 事件处理程序方法 - 混合对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com