【问题标题】:Javascript function doesn't run normally with JSP使用 JSP 无法正常运行 Javascript 函数
【发布时间】: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


【解决方案1】:

问题已解决,您不应将函数命名为“click”,它与“onclick”重复

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-17
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多