123
rated 0 times
[
129]
[
6]
/ answers: 1 / hits: 15119
/ 12 Years ago, mon, august 20, 2012, 12:00:00
I tried to start to work with backbone.js, but I found the Event does not work when I do NOT use 'body' as the View's el.
Here is the code. You can save it as a html file and run it.
<html>
<body>
<button id='openEssay'>test</button>
<div id='div' style='width:100px;height:100px;'></div><script src=https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js></script>
<script src=http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js></script>
<script src=http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js></script><script>
(function($){
var AppView = Backbone.View.extend({
el:'body',//success
//fail el:'#div',
//fail tagName: 'li',
//fail id:'div',
initialize:function(){
_.bindAll(this, 'openEssay');
},
events:{
'click button#openEssay':'openEssay'
},
openEssay:function(){
alert('a');
}
});
var app = new AppView();
})(jQuery);
</script>
</body>
</html>
More From » backbone.js