backbone.js视图undeligateevent

Backbone.js undeligateEvent方法用于从DOM中删除视图的委托事件。
句法:

delegateEvents()

【backbone.js视图undeligateevent】让我们举个例子。
请参阅以下示例:
< !DOCTYPE html> < head> < title>View Example< /title> < script src="http://img.readke.com/220416/0IG02345-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/0IG0ED-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/0IG035R-2.jpg" type="text/javascript">< /script> < /head> < body> < div id="mydiv">< /div> < script type="text/javascript"> var ViewDemo = Backbone.View.extend({events: {'click button': 'undelegateFunc'}, undelegateFunc: function () { document.write("Do something to undelegate..."); $(this.el).undelegate('button', 'click'); }, render: function () {this.$el.html('< button>Click to undelegate< /button>'); }, initialize:function(){this.render(); } }); var myview = new ViewDemo({el: '#mydiv'}); < /script> < /body> < /html>

输出:
将以上代码保存在undeligate.html文件中,然后在新的浏览器中打开此文件。
backbone.js视图undeligateevent

文章图片
单击后,你将得到以下结果:
backbone.js视图undeligateevent

文章图片

    推荐阅读