我收到未捕获的语法错误
意外标识符 - underscore.min.js 24.
一旦我在模板中添加此复选框代码,就会出现错误:
template: _.template('<h3>'+'<input type=checkbox'+'<% if(status === "complete") print("checked") %> />' + '<% = name %></h3>'),
我猜错误在模板的复选框代码中,我不知道那是什么。
下面是我的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.4/underscore-min.js"></script>
<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/backbone.js/0.3.3/backbone-min.js"></script>
</body>
<script>
var Friend = Backbone.Model.extend({});
var friend = new Friend ({ name:'phani'});
var FriendView = Backbone.View.extend({
el:'body',
tagName:'article',
id:'my-friend',
className:'hello-friend',
//template
template: _.template('<h3>'+'<input type=checkbox'+'<% if(status === "complete") print("checked") %> />' + '<% = name %></h3>'),
//event
events:{
"click h3":"alertStatus"
},
alertStatus: function(e){
alert("Hey you clicked the h3!");
},
render:function(){
var attributes = this.model.toJSON();
$(this.el).html(this.template(attributes));
}
});
var friendView = new FriendView({model:friend});
friendView.render();
console.log(friendView.el);
</script>