[英]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文件。文件:
function showPopUp() {
var isConfirmed = confirm("Are you sure you want to logout ?");
if (isConfirmed) {
window.location = "./logout";
}
}
function isEmpty(){
console.log("isEmpty");
}
我正在将文件导入到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>
当使用shopPupUp功能激活输入上的onkeyup时,它可以正常工作,显示确认并可以。
但是当我使用isEmpty函数激活输入上的onkeyup时,我在控制台中收到以下错误:
未捕获的ReferenceError:在HTMLInputElement.onkeyup上未定义isEmpty
有人有想法么 ?
Chrome中的 Ctrl + Shift + Del
组合Ctrl + Shift + Del
。 选中“缓存的图像和文件”复选框,然后单击“清除浏览数据”解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.