js实现,,是否确认删除,如果“否”,则返回,如果“是”,则删除

白白白白白白白白白 2017-10-28 03:30:47
刚学习jsp,通过servlet已经初步实现点击“删除”按钮,即可实现删除这条数据,现在想增加一个功能,就是点击“删除”按钮,弹出”是否确认删除“,如果“否”,则返回,如果“是”,则删除,就是删除按钮的onclick点击时,如果选择否,则不跳转后面的location,求大神支招

<%@ page language="java" import="java.util.*,cn.edu.hezeu.jsp.pojo.*,java.text.*,cn.edu.hezeu.jsp.service.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'main.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script src="js/jquery.js"></script>
<script type="text/javascript">
function del(){
var del=confirm("您确定要删除此条记录?");
if(del==true){

}else{
return;
}
}
</script>
</head>

<body>
所有学生的信息如下:
<%List<Student> students=(List<Student>)request.getAttribute("stuList"); %>
<table border="1">
<tr>
<th>序号</th>
<th>学号</th>
<th>密码</th>
<th>真实姓名</th>
<th>操作</th>
</tr>
<%for(Student stu:students){ %>
<tr>
<td id="id"><%=stu.getId() %></td>
<td><%=stu.getUsername() %></td>
<td><%=stu.getPassword() %></td>
<td><%=stu.getRealname() %></td>
<td>
<button name="edit" onclick="location.href='StudentManager?id=<%=stu.getId() %>&operator=edit'">修改</button>
<button name="delete" class="buttondelete" onclick="del();location.href='StudentManager?id=document.getElementById("id").value() & operator=delete'">删除</button>
</td>
</tr>
<%} %>
<tr>
<td colspan="5"><a href="regist.jsp">增加</a></td>
</tr>
</table>
</body>
</html>
...全文
429 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
天际的海浪 2017-10-28
  • 打赏
  • 举报
回复


<%@ page language="java" import="java.util.*,cn.edu.hezeu.jsp.pojo.*,java.text.*,cn.edu.hezeu.jsp.service.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'main.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="js/jquery.js"></script>
	 <script type="text/javascript">
	function del(){
		return confirm("您确定要删除此条记录?");
	}
</script>
  </head>
  
  <body>
   所有学生的信息如下:
   <%List<Student> students=(List<Student>)request.getAttribute("stuList"); %>
   <table border="1">
   		<tr>
   			<th>序号</th>
   			<th>学号</th>
   			<th>密码</th>
   			<th>真实姓名</th>
   			<th>操作</th>
   		</tr>
   		<%for(Student stu:students){ %>
   			<tr>
   				<td id="id"><%=stu.getId() %></td>
   				<td><%=stu.getUsername() %></td>
   				<td><%=stu.getPassword() %></td>
   				<td><%=stu.getRealname() %></td>
   				<td>
   					<button name="edit" onclick="location.href='StudentManager?id=<%=stu.getId() %>&operator=edit'">修改</button>
   					<button name="delete" class="buttondelete" onclick="if(del()) location.href='StudentManager?id=<%=stu.getId() %>&operator=delete'">删除</button>
   				</td>
   			</tr>
   		<%} %>
   		<tr>
   			<td colspan="5"><a href="regist.jsp">增加</a></td>
  		</tr>
   </table>
  </body>
</html>

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧