admin管理员组文章数量:1317115
(function ($) {
window.AppView = Backbone.View.extend({
el: $("body"),
events: {
"click #add-friend": "showPrompt",
},
showPrompt: function () {
var friend_name = prompt("Who is your friend?");
}
});
var appview = new AppView;
})(jQuery);
- Can anyone explain me what is
el
here. Is it element? - Does the el argument accept object, if so can i pass my custom view object where my button or elements need to be added...
(function ($) {
window.AppView = Backbone.View.extend({
el: $("body"),
events: {
"click #add-friend": "showPrompt",
},
showPrompt: function () {
var friend_name = prompt("Who is your friend?");
}
});
var appview = new AppView;
})(jQuery);
- Can anyone explain me what is
el
here. Is it element? - Does the el argument accept object, if so can i pass my custom view object where my button or elements need to be added...
2 Answers
Reset to default 5- Yes it's a DOM element.
- No you cannot pass a custom object. You either specify an existing element, or creating one from the
tagName
,className
,id
andattributes
properties of the view. If you don't specify an element, it defaults to adiv
It's all in the official documentation actually...
Alladnian answered it but I would add that when using el
you can make use of $el
which is a cached jQuery object of your view element.
So you can always simply pass only the tag you wish to use (for consistency, brevity and flexibility) and then reference it as $el
to make use of it as a jQuery object.
this.$el.addClass("active");
本文标签: javascriptbackbonejs and el attributeStack Overflow
版权声明:本文标题:javascript - backbone.js and el attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742022375a2414914.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论