MchengY 2022-10-21 10:28 采纳率: 90.5%
浏览 25
已结题

用jsp写了个表格删除和添加,删除用了触发事件按,但是触发事件没有反应怎么会是。

问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图

```javascript
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>表格的添加和删除</title>
</head>
<script>
    window.onload=function(){
        function del(object){
            var table=object.parentNode.parentNode.parentNode;
            var tr=object.parentNode.parentNode;
            table.removeChild(tr);
        }
    }
</script>
<body>
<%!
public class Teacher{
    int id;
    String name;
    String brithday;
    String address;
    double salary;
    String operate;
    public Teacher(int id,String name,String brithday,String address,double salary,String operate){
        this.id=id;
        this.name=name;
        this.brithday=brithday;
        this.address=address;
        this.salary=salary;
        this.operate=operate;
    }
    int getId()
    {
        return id;
    }
    String getName()
    {
        return name;
    }
    String getBrithday()
    {
        return brithday;
    }
    String getAddress()
    {
        return address;
    }
    double getSalary()
    {
        return salary;
    }
    String getOperate()
    {
        return operate;
    }
}
%>
<%
Teacher[] teacher=new Teacher[10];
teacher[0]=new Teacher(11201,"文华","1980-6-12","淮南",6600,"英语");
teacher[1]=new Teacher(11202,"余祥","1984-7-23","合肥",7000,"数据结构");
teacher[2]=new Teacher(11203,"于资","1985-2-1","南京",6700,"离散");
teacher[3]=new Teacher(11204,"卜悦","1991-5-16","合肥",6600,"高等数学");
teacher[4]=new Teacher(11205,"王毅","1987-7-16","芜湖",6600,"线性代数");
teacher[5]=new Teacher(11206,"赵鑫","1988-3-26","合肥",6600,"java");
teacher[6]=new Teacher(11207,"丁莹","1990-11-21","蚌埠",6600,"c++");
teacher[7]=new Teacher(11208,"程明","1984-12-17","合肥",6600,"c语言");
teacher[8]=new Teacher(11209,"张强","1986-9-16","阜阳",6600,"毛概");
teacher[9]=new Teacher(11210,"周霞","1991-5-26","合肥",6600,"思修");
%>
<table align="center" border="2" width="70%">
<tr>
<th>教工号</th><th>姓名</th><th>出生日期</th><th>籍贯</th><th>薪水</th><th>课程</th><th>操作</th>
</tr>
<%
int i;
for(i=0;i<teacher.length;i++){%>
<tr>
<td align="center"><%=teacher[i].getId() %></td>
<td align="center"><%=teacher[i].getName() %></td>
<td align="center"><%=teacher[i].getBrithday() %></td>
<td align="center"><%=teacher[i].getAddress() %></td>
<td align="center"><%=teacher[i].getSalary() %></td>
<td align="center"><%=teacher[i].getOperate() %></td>
<td align="center"><a href="javascript:void(0);" onclick="del(this)">删除</a> 
<a href="#">修改</a>
</td>
<%}%>
</table>
</body>
</html>


运行结果及报错内容

写个了删除的触发事件但是没有反应是怎么回事

  • 写回答

2条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-10-21 10:33
    关注

    如果你要手动触发就把这个函数再拎出来一份,不然你这个只有加载页面触发,然后下边点击的时候没有这个del函数呀

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月29日
  • 已采纳回答 10月21日
  • 创建了问题 10月21日

悬赏问题

  • ¥15 MATLAB代码求涡量
  • ¥100 采用栈和深度优先算法对我的代码进行修改显示路径
  • ¥15 pointnet2包安装
  • ¥20 射频功率问题,解答者有酬谢!
  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00
  • ¥15 odbc代码新增sqlserver数据源