<script src="JS/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(function () {//所有删除按钮的单击事件
$(".deletes").click(function () {
if (!confirm("确定要删除么?")) {
return false;
}
});
});
</script>
using System.Collections.Generic;
using System.Web;
using BLL;
using Model;
using System.Text;
using System.IO;
namespace WebApp2019
{
/// <summary>
/// UserInfoList 的摘要说明
/// </summary>
public class UserInfoList : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/html";
//context.Response.Write("Hello World");
UserInfoBLL bll = new UserInfoBLL();
List<UserInfo> list= bll.GetUserInfoList();
StringBuilder sb = new StringBuilder();
foreach (UserInfo userInfo in list)
{
sb.AppendFormat("<tr>" +
"<td>{0}</td>" +
"<td>{1}</td>" +
"<td>{2}</td>" +
"<td>{3}</td>" +
"<td><a href='ShowDetail.ashx?id={0}'>详细</a></td>" +
"<td><a href='DeleteUser.ashx?id={0}' class='deletes'>删除</a></td>" +//类选择器用于html模板javascript脚本点击删除提示
"<td><a href='EditUserRead.ashx?id={0}'>编辑</a></td>" +
"</tr>",
userInfo.Id,
userInfo.UserName,
userInfo.UserPwd,
userInfo.RegTime);
}
string fullPathHtmlFile = context.Request.MapPath("UserInfoList.html");//由于UserInfoList.ashx与UserInfoList.html在同一个文件夹下,直接写名字即可
string htmlFileContent = File.ReadAllText(fullPathHtmlFile);
htmlFileContent = htmlFileContent.Replace("$tbody", sb.ToString());
context.Response.Write(htmlFileContent);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
<script type="text/javascript">
//DOM写法
window.onload = function () {
var datas = document.getElementsByClassName("deletes");
var datasLength = datas.length;
for (var i = 0; i < datasLength; i++) {
datas[i].onclick = function () {
if (!confirm("确定要删除么?")) {
return false;
}
}
}
}
//---------------------jquery方式
<%-- < script src = "JS/jquery-1.7.1.js" ></ script>
<script type="text/javascript">
$(function () {//所有删除按钮的单击事件
$(".deletes").click(function () {
if (!confirm("确定要删除么?")) {
return false;
}
});
});
</ script>--%>
</script>