简体   繁体   English

JavaScript 和 JQuery 代码如何从 MVC 视图移动到 Visual Studio 2017 的外部 .js 文件?

[英]How is JavaScript and JQuery code moved from an MVC View to an external .js file for Visual Studio 2017?

I am getting squiggly green underlines in JQuery code I have moved from my MVC View to an external .js file.我从我的 MVC 视图移动到外部 .js 文件的 JQuery 代码中出现波浪形绿色下划线。 The code is fine in an MVC View but not in the external file.代码在 MVC 视图中很好,但不在外部文件中。 What needs to be done to the external .js file in my Visual Studio 2017 project so the code is recognized?需要对我的 Visual Studio 2017 项目中的外部 .js 文件做什么才能识别代码? Below is a picture of JQuery code which Visual Studio 2017 is showing problems with in a .js file where I pasted code to from my MVC View:下面是 JQuery 代码的图片,Visual Studio 2017 在 .js 文件中显示了问题,我将代码从我的 MVC 视图粘贴到该文件中:

在此处输入图片说明

Below is an example of one of the reported problems in Visual Studio 2017:下面是 Visual Studio 2017 中报告的问题之一的示例:

在此处输入图片说明

This code is fine in my MVC View with no such green underlines.这段代码在我的 MVC 视图中很好,没有这样的绿色下划线。 What is the problem with .js file I am using and how do I fix it?我正在使用的 .js 文件有什么问题,我该如何解决? Thanks in advance.提前致谢。

When you are using .js (external javascript file) then you dont have to define当您使用 .js(外部 javascript 文件)时,您不必定义

<script type="text/javascript">
//Your JS Code
</script>

So Just remove <script> tags.所以只需删除<script>标签。

Now your .js files looks like现在你的 .js 文件看起来像

//Your JS Code //你的JS代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM