[英]backbone.js and el attribute
(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);
el
here. el
这里。 Is it element? tagName
, className
, id
and attributes
properties of the view. tagName
, className
, id
和attributes
属性创建一个元素。 If you don't specify an element, it defaults to a div
div
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. Alladnian回答了这个问题,但我想补充一点,当你使用
el
你可以使用$el
,它是你视图元素的缓存jQuery对象。
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. 因此,您始终只需传递您希望使用的标记(为了一致性,简洁性和灵活性),然后将其作为
$el
引用,以将其用作jQuery对象。
this.$el.addClass("active");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.