无法在html中调用.js(使用淘汰赛)

ake*_*eth 0 html javascript knockout-2.0 knockout.js

我是淘汰使用knockout2.1.0的新手.我有一个外部java脚本文件,但它没有在我的html文件中调用.我不明白.

我在我的html文件中添加了以下内容

  <script src="Scripts/TestJavascript.js"></script>
Run Code Online (Sandbox Code Playgroud)

JS档案

///<reference path="~/Scripts/jquery-1.8.1.min.js">
///<reference path="~/Scripts/knockout-2.1.0.debug.js">
$(function AppViewModel() {
this.firstName = ko.observable("rash");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function(){
    return this.firstName() + " " + this.lastName();
}, this);
})
ko.applyBindings(new AppViewModel());
Run Code Online (Sandbox Code Playgroud)

谢谢.

Dan*_*ite 5

您没有创建ViewModel.你将它传递给jquery.

尝试

var AppViewModel = function() {
  this.firstName = ko.observable("rash");
  this.lastName = ko.observable("Bertington");
  this.fullName = ko.computed(function(){
      return this.firstName() + " " + this.lastName();
  }, this);
})
ko.applyBindings(new AppViewModel());
Run Code Online (Sandbox Code Playgroud)