html <script src="" > 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19374138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html <script src="" > not working
提问by karz
i have the following login.html page for login located in design folder.
我有以下 login.html 登录页面位于设计文件夹中。
<html>
<head>
<title>Login Page</title>
<script src="../Script/login.js">
</script>
</head>
<body>
<h3> Login</h3>
<form name="login">
Location code : <select name="ddl1"><br>
<option value="loc1" size=20>LH</option>
<option value="loc2">AT</option>
<option value="sel" selected>-------select------</option>
</select>
<br><br>
Enter UserName : <input type="Text" name="inp1" size=20><br><br>
Enter Password : <input type="password" name="pwd1" size=20><br><br>
<button type="button" name="login" onclick="log()">Login</button>
</form>
</body>
</html>
and also i have onother folder named scripts that contains the the following login.js file
并且我还有一个名为 scripts 的文件夹,其中包含以下 login.js 文件
function log()
{
var li=parent.head.document.getElementById('lin');
var lo=parent.head.document.getElementById('lou');
var passid = document.login.pwd1.value;
var passid_len = passid.length;
var un=document.login.inp1.value;
var e = document.getElementById("ddl1");
var strUser = e.options[e.selectedIndex].value;
if(strUser=="loc1" || strUser=="loc2")
{
if (passid_len >= 5)
{
if(un=="admin")
{
parent.nav1.location.href = 'nav_admin.html';
document.write("Hello admin");
li.style.display = "none";
lo.style.display = "";
}
else if(un=="clerec")
{
parent.nav1.location.href = 'nav_clerk_reception.html';
document.write("Hello reception clerk");
li.style.display = "none";
lo.style.display = "";
}
else if(un=="cledep")
{
parent.nav1.location.href = 'nav_clerk_departemnt_operations.html';
document.write("Hello dept clerk");
li.style.display = "none";
lo.style.display = "";
}
else if(un=="guest")
{
parent.nav1.location.href = 'nav_guest.html';
document.write("Hello Guest");
li.style.display = "none";
lo.style.display = "";
}
else
{
document.write("Wrong user name and password");
}
}
else
{
document.write("password should be minimum 5 characters");
}
}
else
{
document.write("Choose Location");
}
}
function fnlog1()
{
var lo=parent.head.document.getElementById('lou');
var li=parent.head.document.getElementById('lin');
lo.style.display = "none";
li.style.display = "";
parent.nav1.location.href = 'navigate.html';
}
when i click log in
button nothing works....no redirection takes place....html page does not call log()
function....
当我点击log in
按钮没有任何作用....没有重定向发生....html页面不调用log()
函数....
回答by Afzaal Ahmad Zeeshan
First you are linking the file that is here:
首先,您要链接此处的文件:
<script src="../Script/login.js">
Which would lead the website to a file in the Folder Script
, but then in the second paragraph you are saying that the folder name is
这将导致网站到文件夹中的文件Script
,但是在第二段中,您说文件夹名称是
and also i have onother folder named scripts that contains the the following login.js file
并且我还有一个名为 scripts 的文件夹,其中包含以下 login.js 文件
So, this won't work! Because you are not accessing the correct file. To do that please write the code as
所以,这行不通!因为您没有访问正确的文件。为此,请将代码编写为
<script src="/script/login.js"></script>
Try removing the ..
from the beginning of the code too.
也尝试..
从代码的开头删除。
This way, you'll reach the js file where the function would run!
这样,您将到达运行该函数的 js 文件!
Just to make sure:
只想确认一下:
Just to make sure that the files are attached the HTML DOM, then please open Developer Tools (F12) and in the network workspace note each request that the browser makes to the server. This way you will learn which files were loaded and which weren't, and also why they were not!
只是为了确保文件附加到 HTML DOM,然后请打开开发人员工具 (F12) 并在网络工作区中记录浏览器向服务器发出的每个请求。通过这种方式,您将了解哪些文件已加载,哪些未加载,以及为什么没有加载!
Good luck.
祝你好运。
回答by q0re
Your foldername is scripts
?
你的文件夹名是scripts
?
Change
改变
<script src="../Script/login.js">
to
到
<script src='scripts/login.js' type='text/javascript'></script>
回答by BaleineBleue
I was having this problem but i found out that it was a permissions problem I changed my permissions to 0744 and now it works. I don't know if this was your problem but it worked for me.
我遇到了这个问题,但我发现这是一个权限问题,我将权限更改为 0744,现在它可以工作了。我不知道这是否是你的问题,但它对我有用。
回答by vikash bhartia
your folder name is scripts..
你的文件夹名称是脚本..
and you are Referencing it like ../script/login.js
并且您正在像 ../script/login.js 一样引用它
Also make sure that script folder is in your project directory
还要确保脚本文件夹在您的项目目录中
Thanks
谢谢