帝王谷资源网 Design By www.wdxyy.com
核心代码:
<title>asp批量添加修改删除操作示例</title> <% if request.Form("op")="update" then'表单提交 ids=request.Form("ids") if ids<>"" then response.Write "要删除的数据id集合:"&ids&"<br>" '=========数据库删除操作 conn.execute("delete from xxx where id in("&ids&")")'自己注意做安全验证,假定id为数字集合,自己正则RegExp判断有效性,pattern为^\d+(,\d+)*$ end if rows=request.Form("name").count'提交的数据行数据,包括添加/修改的 for i=1 to rows'遍历每行数据 id=request.Form("id").item(i)&"" name=request.Form("name").item(i) sex=request.Form("sex").item(i) age=request.Form("age").item(i) addr=request.Form("addr").item(i) if id<>"" then'修改操作,如果id为数字加isnumeric判断 response.Write "要修改数据行:"&id&"|"&name&"|"&sex&"|"&age&"|"&addr&"<br>" '修改操作 else'添加操作 response.Write "要添加数据行:"&name&"|"&sex&"|"&age&"|"&addr&"<br>" '添加操作 end if next end if %> <form method="post" onsubmit="return check(this)"> <input type="hidden" name="ids" /><!--用于存储要删除记录的id集合--> <input type="hidden" name="op" value="update" /> <table border="1" id="tb" > <tr><th>姓名</th><th>性别</th><th>年龄</th><th>地址</th><th>删除</th></tr> <!-------要修改的数据,自己读取数据库生成,<input type="hidden" name="id" value=""/>存储id--------> <tr> <td><input type="text" value="姓名1" name="name" /></td> <td><input type="text" value="性别1" name="sex" /></td> <td><input type="text" value="年龄1" name="age" /></td> <td><input type="text" value="地址1" name="addr" /></td> <td><input type="button" value="删除" onclick="removeRow(this)" /><input type="hidden" name="id" value="1"/></td> </tr> <tr> <td><input type="text" value="姓名2" name="name" /></td> <td><input type="text" value="性别2" name="sex" /></td> <td><input type="text" value="年龄2" name="age" /></td> <td><input type="text" value="地址2" name="addr" /></td> <td><input type="button" value="删除" onclick="removeRow(this)" /><input type="hidden" name="id" value="2"/></td> </tr> <!-------要修改的数据示例结束--------> <tr><td colspan="5" align="center"><input type="submit" value="提交"/> <input type="button" value="添加新数据行" onclick="addRow()" /></td></tr> </table> </form> <script type="text/javascript"> function removeRow(btn){ if (confirm('确认删除?!')) { var tr=btn.parentNode.parentNode; var id = btn.nextSibling;//注意删除按钮和id这个hidden控件之间不要有空格,要不nextSibling在标准浏览器下是空白节点 if (id.value != '') {//删除是存在的行而不是新增的,则id存储到ids中 btn.form.ids.value += (btn.form.ids.value == '' "text" name="name" />'; td = tr.insertCell(1); td.innerHTML = '<input type="text" name="sex" />'; td = tr.insertCell(2); td.innerHTML = '<input type="text" name="age" />'; td = tr.insertCell(3); td.innerHTML = '<input type="text" name="addr" />'; td = tr.insertCell(4); td.innerHTML = '<input type="button" value="删除" onclick="removeRow(this)" /><input type="hidden" name="id" />';//新增数据行id为空 } function check(f) { var tb = document.getElementById('tb'), ipts; for (var i = 1, j = tb.rows.length - 1; i < j; i++) {//输入验证,去掉第一行表头和最后一行操作 ipts = tb.rows[i].getElementsByTagName('input'); if (ipts[0].value == '') { alert('请输入姓名!'); ipts[0].focus(); return false; } if (ipts[1].value == '') { alert('请输入性别!'); ipts[1].focus(); return false; } if (ipts[2].value == '') { alert('请输入年龄!'); ipts[2].focus(); return false; } if (ipts[3].value == '') { alert('请输入地址!'); ipts[3].focus(); return false; } } } </script>
标签:
asp批量,添加,修改
帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com
暂无评论...
更新日志
2024年10月28日
2024年10月28日
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]