BackboneJS - View El
描述
它定义要使用哪个元素作为视图引用。如果指定,则 this.el 由视图的 tagName、className、id 和 attributes 属性创建。如果没有,则 el 为空的 div。
语法
view.el
示例
<!DOCTYPE html>
<html>
<head>
<title>View Example</title>
<script src = "https://code.jquery.com/jquery-2.1.3.min.js"
type = "text/javascript"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"
type = "text/javascript"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"
type = "text/javascript"></script>
</head>
<script type = "text/javascript">
//'ViewDemo' 是视图类的名称
ViewDemo = Backbone.View.extend ({
//当视图实例化时,此函数被调用
initialize: function(){
document.write("Hello !!!! This is el property...");
}
});
//'viewdemo'是'ViewDemo'类的实例
var viewdemo = new ViewDemo({ el: $("myapp") });
</script>
<body>
<div id = "myapp"></div>
</body>
</html>
输出
让我们执行以下步骤来查看上述代码的工作原理 −
将上述代码保存在 el.htm 文件中。
在浏览器中打开此 HTML 文件。

backbonejs_view.html