在 JSP 中使用单独的 JS 文件不起作用



我有一个JSP,我正在尝试使用JavaScript并将我的JS代码放在一个单独的JS文件中,并在我的JSP中添加对它的url引用,下面是代码片段

.JSP

my JS file(script.js)
function showPopupWindow() {
document.getElementById('popupWindow').style.display = 'block';
}
`<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
<link rel="stylesheet" href="<c:url value="/resources/css/style.css"/>">
<script type="text/javascript" src="<c:url src="/resources/script/script.js"/>"></script>
</head>
<body>
<div id="divpopup" style="display:none;"> Poping up!!</div>
<div><a onclick="showPopupWindow()">create</a></div>
</body>
</html>
`

这里的问题是当我使用单独的 JS 文件时,它对我不起作用。单击创建按钮后没有看到任何结果。

function showPopupWindow(( { document.getElementById('popupWindow'(.style.display = 'block';

}

我的代码的问题是我错误地在我的 JS 函数中为我的div 使用了不同的元素名称,它应该指的是"divpopup"而不是"popupWindow"。现在它正在工作。

最新更新