我在设计文件夹中有以下用于登录的 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>
我还有一个名为 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';
}
当我点击 log in
按钮时没有任何效果....没有重定向发生....html 页面不调用 log()
函数....
最佳答案
首先,您要链接此处的文件:
<script src="../Script/login.js">
这会将网站引导至文件夹 Script
中的文件,但随后在第二段中您说文件夹名称是
and also i have onother folder named scripts that contains the the following login.js file
所以,这行不通!因为您没有访问正确的文件。为此,请将代码编写为
<script src="/script/login.js"></script>
也尝试从代码开头删除 ..
。
这样,您将到达运行该函数的 js 文件!
只是为了确保:
只是为了确保文件附加到 HTML DOM,然后请打开开发人员工具 (F12) 并在网络工作区中记下浏览器向服务器发出的每个请求。通过这种方式,您将了解哪些文件已加载,哪些未加载,以及未加载的原因!
祝你好运。
关于javascript - html 脚本 src =""使用按钮触发重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19374138/