Backbone.js 视图中的 $el 和 el 有什么区别? [英] What is the difference between $el and el in Backbone.js views?

查看:22
本文介绍了Backbone.js 视图中的 $el 和 el 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能说出 Backbone.js 视图中 $elel 的区别吗?

Can you please tell the difference between $el and el in Backbone.js views?

推荐答案

让我们说你这样做

var myel = this.el; // here what you have is the html element, 
                    //you will be able to access(read/modify) the html 
                    //properties of this element,

有了这个

var my$el = this.$el; // you will have the element but 
                      //with all of the functions that jQuery provides like,
                      //hide,show  etc, its the equivalent of $('#myel').show();
                      //$('#myel').hide(); so this.$el keeps a reference to your 
                      //element so you don't need to traverse the DOM to find the
                      // element every time you use it. with the performance benefits 
                      //that this implies.

一个是html元素,另一个是元素的jQuery对象.

one is the html element and the other is the jQuery object of the element.

这篇关于Backbone.js 视图中的 $el 和 el 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆