这是我的代码:
<!DOCTYPE html>
<html>
<head></head>
<body>
<div id="someElement">
<button id="someButton">Click Me</button>
</div>
<script src="jquery-1.4.4.min.js"></script>
<script src="underscore-min.js"></script>
<script src="backbone-min.js"></script>
<script>
MyView = Backbone.View.extend({
events: {
"click #someButton": "clicked"
},
clicked: function (e) {
e.preventDefault();
alert("I was clicked!");
},
render: function () {
var html = "generate some HTML, here";
$(this.el).html(html);
}
});
$(function () {
var myView = new MyView();
myView.render();
$("#someElement").html(myView.el);
});
</script>
</body>
</html>
我的问题是:如何等待点击按钮触发点击事件?
(顺便说一句,代码部分来自http://lostechies.com/derickbailey/2011/11/09/backbone-js-object-literals-views-events-jquery-and-el/)