本文概述
- 参数说明
句法:
object.trigger(event, [args])
参数说明事件:用于绑定对象。
args:用于将值/参数传递给回调函数。
让我们举个例子。
请参阅以下示例:
<
!DOCTYPE html>
<
head>
<
title>Event Trigger Example<
/title>
<
script src="http://img.readke.com/220416/0159262132-0.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/01592A9E-1.jpg" type="text/javascript"><
/script>
<
script src="http://img.readke.com/220416/0159264625-2.jpg" type="text/javascript"><
/script>
<
/head>
<
body>
<
script type="text/javascript">
//Created an object 'myVal' and extended it using Backbone.Events method
var myVal = _.extend({title:'srcmini', site:'www.srcmini.com'}, Backbone.Events);
//The on() method will bind the callback function to an object
myVal.on('myFunc', function () {
document.write("The triggered value for site is: ");
document.write(this.site);
//value of site will get displayed by referring the current object
});
// The trigger() method triggers the 'myFunc' event on 'myVal'
myVal.trigger('myFunc');
<
/script>
<
/body>
<
/html>
输出:
【backbone.js trigger事件】将上面的代码保存在trigger.html文件中,然后在浏览器中打开此文件。
文章图片
推荐阅读
- backbone.js模型escape
- backbone.js模型set
- backbone.js模型get
- backbone.js模型扩展
- backbone.js模型初始化
- backbone.js模型教程
- backbone.js listentoonce事件
- backbone.js stoplistening事件
- backbone.js once事件