gpt4 book ai didi

javascript - CanJS future 元素事件绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 02:02:17 24 4
gpt4 key购买 nike

CanJS documentation有一个这样的例子:

var Todos = can.Control.extend({
init: function( element , options ) { ... },

'li click': function( li ) { ... },
'li .destroy {destroyEvent}': function( el, ev ) {
// previous destroy code here
}
});
// create Todos with this.options.destroyEvent
new Todos( '#todos', { destroyEvent: 'mouseenter' } );

但是,如果在调用 new Todos 之后创建 #todos,则不会有任何事件绑定(bind)到 future 元素,或者如果 Todos 中的方法> 根据需要删除预先创建的 #todos 虚拟对象。如何在控件中重新绑定(bind)自定义事件? Control 实例化调用之后?

最佳答案

只需使用 Control.on(); http://canjs.com/docs/can.Control.prototype.on.html

您可以指定要监听哪个事件,或者只调用不带参数的函数,例如控件监听所有事件。

关于javascript - CanJS future 元素事件绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280002/

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