html脚本src =“"使用按钮触发重定向 [英] html script src="" triggering redirection with button

查看:187
本文介绍了html脚本src =“"使用按钮触发重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设计文件夹中具有以下用于登录的login.html页面.

<html>
<head>
<title>Login Page</title>
<script src="../Script/login.js">

</script>

</head>
<body>
<h3> Login</h3>
<form name="login">
Location code  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp; <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 &nbsp;&nbsp;:  &nbsp;&nbsp;<input type="Text" name="inp1" size=20><br><br>
Enter Password &nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;  <input type="password" name="pwd1" size=20><br><br>

<button type="button" name="login" onclick="log()">Login</button> 

</form>

</body>
</html>

,我还有另一个名为script的文件夹,其中包含以下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()函数....

when i click log in button nothing works....no redirection takes place....html page does not call log() function....

推荐答案

首先,您要链接此处的文件:

First you are linking the file that is here:

<script src="../Script/login.js"> 

这会将网站引导到文件夹Script中的文件,但是在第二段中,您说的是文件夹名称

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的onother文件夹,其中包含以下login.js文件

and also i have onother folder named scripts that contains the the following login.js file

所以,这行不通!因为您没有访问正确的文件.为此,请将代码编写为

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.

这样,您将到达该函数将运行的js文件!

This way, you'll reach the js file where the function would run!

只需确保

仅要确保文件附加了HTML DOM,然后打开开发人员工具(F12),并在网络工作区中记下浏览器对服务器的每个请求.这样,您将了解哪些文件已加载,哪些文件未加载,以及为什么未加载这些文件!

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脚本src =“"使用按钮触发重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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