Javascript TypeScript:使用jQuery会导致引用错误
我尝试使用打字脚本。作为以前的javascript用户,我不想放弃jQuery 所以我在互联网上搜索了我的博客,找到了大量解释如何使用它的网站。我使用Visual Studio 2012 这是我的第一次尝试:Javascript TypeScript:使用jQuery会导致引用错误,javascript,typescript,Javascript,Typescript,我尝试使用打字脚本。作为以前的javascript用户,我不想放弃jQuery 所以我在互联网上搜索了我的博客,找到了大量解释如何使用它的网站。我使用Visual Studio 2012 这是我的第一次尝试: /// <reference path="jquery.d.ts" /> class Person { constructor(name: string) { this.name = name; } name: string;
/// <reference path="jquery.d.ts" />
class Person {
constructor(name: string) {
this.name = name;
}
name: string;
}
function greeter(person: Person) {
return "hallo " + person.name;
}
var person = new Person("bert");
$(document).ready(function () {
var message = greeter(person);
jQuery("#content")[0].innerHTML = message;
});
//
班主任{
构造函数(名称:string){
this.name=名称;
}
名称:字符串;
}
功能迎宾员(人:人){
返回“hallo”+person.name;
}
var人员=新人员(“伯特”);
$(文档).ready(函数(){
var消息=迎宾员(人);
jQuery(“#content”)[0].innerHTML=message;
});
我可以构建解决方案,但如果我打开我的网站,它会出现javascript错误:
ReferenceError:$未定义
有什么想法吗?您仍然需要加载jquery.js(例如,使用脚本标记),就像您没有使用TypeScript一样。愚蠢的问题,但是,您是否在页面上加载jquery?您只引用了jQuery定义,实际上并没有使用.ts编译它,所以您仍然需要将它添加到脚本标记.newbie中。。。谢谢你的帮助。。