今天突发苦恼,为什么js没有智能提示,转到定义无效?我的开发工具是vs2015...
于是,我开始网上搜索解决方案...
打开项目,在脚本文件根目录中新建一个空白文件“_references.js”。
右击“_references.js”,见下图,点击“自动同步JavaScript引用”、“更新JavaScript引用”
工具 - 选项 - 文本编辑器 - JavaScript - IntelliSense,在“将引用添加到当前组”输入框中输入“_references.js”相对路径,并点击确定,结果如下:
我们自定义的js函数,添加类似这样的注释
1 function ajaxServiceForUploadFile(_url, _data, successFn, _async, _dataType) { 2 /// <signature> 3 /// <summary> 4 /// ajax上传文件 5 /// </summary> 6 /// <param name="_url" type="string">请求url</param> 7 /// <param name="_data" type="var">发送到服务器的数据</param> 8 /// <param name="successFn" type="function">发送请求成功回调</param> 9 /// <param name="_async" type="bool">同步或异步请求</param> 10 /// <param name="_dataType" type="string">预期服务器返回的数据类型</param> 11 /// </signature> 12 _async = _async == null || _async == undefined ? true : _async; 13 _dataType = _dataType == null || _dataType == undefined ? "json" : _dataType; 14 $.ajax({ 15 type: "post", 16 url: _url, 17 async: _async,//默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。 18 contentType: false,//默认值: "application/x-www-form-urlencoded"。发送信息至服务器时内容编码类型。 19 data: _data,//发送到服务器的数据。 20 dataType: _dataType,//预期服务器返回的数据类型。 21 cache: false,//默认值: true,dataType 为 script 和 jsonp 时默认为 false。设置为 false 将不缓存此页面。 22 processData: false, 23 success: function (data, textStatus) { 24 if (successFn != null) { 25 successFn(data); 26 } 27 }, 28 error: function (XMLHttpRequest, textStatus, errorThrown) { 29 layeralert(errorThrown.message); 30 } 31 }); 32 }
调用该函数时,输入函数名及左括号,即自动显示该函数说明
但是,我有个疑问,js自带的函数,比如substr,无法点出提示,有没有大神知道??
网上有人推荐TypeScript,我也下载安装了。初次体验,功能蛮强大的。
新建xxx.ts文件,在xxx.ts文件中写上js代码后,同名的js文件会自动生成。
虽然TypeScript有自己的一套语法,但是它强大之处在于,鼠标悬浮在函数名上,那个智能提示赞赞赞。
我好想知道,如何才能做出这样的效果...