我有以下代码,但javascript似乎根本没有执行。
我在这里缺少什么东西吗?
<!doctype html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Backbonejs</title>
</head>
<body>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js">
<script type="text/javascript">
Person = Backbone.Model.extend({
initialize: function(){
console.log('hello world');
this.bind('change:name', function(){
console.log(this.get('name') + "is now the val for name");
});
},
defaults: {
name: "Bob hope",
height: "unknown"
},
validate: function(attributes){
if(attributes.name == "Joe"){
return "Uh oh, you're name is Joe!";
}
}
});
var person = new Person();
person.set({name: "Joe", height: "6 feet"});
</script>
</body>
</html>
答案 0 :(得分:3)
您缺少关闭script
代码,它们是强制性的:
<script type="text/javascript" src="[...]underscore-min.js"></script>
<script type="text/javascript" src="[...]backbone-min.js"></script>
没有它们,看起来Backbone永远不会被加载。
答案 1 :(得分:-2)
如果您在浏览器中没有任何错误,则表示您必须在加载页面时执行此代码或包含jQuery库。