2017-08-22 94 views
0

問題與外部js文件

function showPopUp() { 
 
\t var isConfirmed = confirm("Are you sure you want to logout ?"); 
 
\t 
 
\t if (isConfirmed) { 
 
\t \t window.location = "./logout"; 
 
\t } 
 
}; 
 

 
function isEmpty(){ 
 
\t 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> 
 
\t <form id='login-form' action="./login" method='POST'> 
 
\t <label></label> 
 
    \t \t <input onkeyup="isEmpty()" type="text" name="userName" placeholder="Username" required> 
 
    \t \t <input onkeyup="isEmpty()" type="password" name="password" placeholder="Password" required> 
 
    \t \t <button type='submit'>Login</button> 
 
    \t \t <label><a href="./register">Register</span></label> 
 
\t </form> 
 
\t 
 
</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時,它是wo完美地證明確認是顯示,並且很好。

但是,當我激活的onkeyup與IsEmpty函數我收到以下錯誤在控制檯輸入:

未捕獲的ReferenceError:是的isEmpty不HTMLInputElement.onkeyup定義

任何人有任何想法?

+0

你有另一個輸入的地方,你有'onkeyup = Empty()'而不是'onkeyup = isEmpty()'? –

+0

也不應該像在'onkeyup =「isEmpty()」'這樣的引號中插入函數嗎? –

+2

請提供一個片段或小提琴,讓我們重現這個問題。 – trincot

回答

0

Chrome中的Ctrl + Shit + Del。檢查緩存的圖像和文件複選框,然後單擊清除瀏覽數據修復了問題。希望它有助於某人:D。