【发布时间】:2021-12-11 10:45:26
【问题描述】:
我有一个使用脚本运行的 JSP 页面,“console.log”或“alert”运行正常,但功能不起作用,当我检查 Chrome 开发工具时,id/class 仍然检索事件侦听器,但它不起作用(如 onclick)
<%@ page import="entity.Product" %>
<%@ page import="entity.Category" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/Home.css" type="text/css"/>
<link rel="stylesheet" href="css/grid.css" type="text/css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<link rel="stylesheet" href="fontawesome-free-5.15.4-web/css/all.min.css" type="text/css"/>
<link rel="stylesheet" href="css/Header.css" type="text/css"/>
<link rel="stylesheet" href="css/Footer.css" type="text/css"/>
</head>
<script type="text/javascript">
console.log(1); //work normally
function click() { //doesn't work
alert('home');
}
</script>
<body>
<div class="body" onclick="click()">
</div>
</body>
</html>
【问题讨论】:
-
能否分享整个jsp文件的代码以便发现问题
-
确定我编辑了我的文件代码
-
当我在控制台上写“click()”时,仍然会弹出警报,但是当我单击“body”时,功能不起作用
标签: javascript jsp