无法将本地Javascript文件附加到HTML [英] Can't attach local Javascript file to HTML

查看:75
本文介绍了无法将本地Javascript文件附加到HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法将本地Javascript文件附加到页面:

I can't seem to attach my local Javascript file to the page:

<head>
<title>My Website</title>
<link rel="stylesheet" type="text/css" href="Main.css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">     </script>
</head>
<body ng-app="VideoGamesApp">

<div class="Main" ng-controller="myCtrl">
    <div>
       <p>{{test}}</p>
    </div>

</div>
<script type="text/javascript" src='C:/Application/Application.js'></script>
</body>

脚本:

var app = angular.module('VideoGamesApp', []);

app.controller('myCtrl', function ($scope) {
    $scope.test = "Success";
});    

当我直接在页面中编写脚本时,它可以工作,但是当我将其与"src"链接时,则不起作用.

When I write the script directly in the page it works, but not when i link it with "src".

推荐答案

src路径是相对于html文件的.如果两者都在同一目录中,请尝试:

The src path is relative to the html file. If both are in the same directory, then try:

<script type="text/javascript" src='Application.js'></script>

如果在子目录中

<script type="text/javascript" src='dirName/Application.js'></script>

如果在父目录中

<script type="text/javascript" src='../Application.js'></script>

但是,请确保JS文件位于网站根目录的层次结构中的某个位置,该根目录是Web服务器使用的根文件夹.

However, make sure that the JS file is somewhere in the hierarchy of the root directory of your website, that is the root folder that your web server uses.

这篇关于无法将本地Javascript文件附加到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆