简体   繁体   中英

Issue with external .js file

 function showPopUp() { var isConfirmed = confirm("Are you sure you want to logout ?"); if (isConfirmed) { window.location = "./logout"; } }; function isEmpty(){ console.log("isEmpty"); }; 
 @CHARSET "ISO-8859-1"; form { margin:0 auto; width:300px } input { margin-bottom:3px; padding:10px; width: 100%; border:1px solid #CCC } button { padding:10px } label { cursor:pointer } 
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript" src="/MyProject/js/customJavaScript.js"></script> <link href="/MyProject/css/LoginRegister.css" rel="stylesheet"/> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Login</title> </head> <body> <form id='login-form' action="./login" method='POST'> <label></label> <input onkeyup="isEmpty()" type="text" name="userName" placeholder="Username" required> <input onkeyup="isEmpty()" type="password" name="password" placeholder="Password" required> <button type='submit'>Login</button> <label><a href="./register">Register</span></label> </form> </body> </html> 

js file with two functions in. The File:

function showPopUp() {
var isConfirmed = confirm("Are you sure you want to logout ?");

    if (isConfirmed) {
       window.location = "./logout";
    }
}

function isEmpty(){
     console.log("isEmpty");
}

I am importing the file in the jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<c:url value='/js/customJavaScript.js'/>"></script>
<link href="<c:url value="/"/>css/LoginRegister.css" rel="stylesheet"/>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Login</title>
</head>
<body>
   <form id='login-form' action="./login" method='POST'>
   <label>${errorMsg}</label>
      <input onkeyup=showPopUp() type="text" name="userName" placeholder="Username" required>
    <input onkeyup=isEmpty() type="password" name="password" placeholder="Password" required>
    <button type='submit'>Login</button>
    <label><a href="./register">Register</span></label>
</form>
<c:remove var="errorMsg" scope="session"/></body></html>

When activate the onkeyup on the input with the shopPupUp function it is working perfectly the confirm is show and it is fine.

But when i activate the onkeyup on the input with the isEmpty function i am getting the following error in the console:

Uncaught ReferenceError: isEmpty is not defined at HTMLInputElement.onkeyup

Anyone have any ideas ?

The combination Ctrl + Shift + Del in Chrome . Check the cached imaged and files checkbox and click on Clear Browsing Data fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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