asp批量添加修改刪除操作示例代碼
核心代碼:
<title>asp批量添加修改刪除操作示例</title>
<%
if request.Form("op")="update" then'表單提交
ids=request.Form("ids")
if ids<>"" then
response.Write "要?jiǎng)h除的數(shù)據(jù)id集合:"&ids&"<br>"
'=========數(shù)據(jù)庫(kù)刪除操作 conn.execute("delete from xxx where id in("&ids&")")'自己注意做安全驗(yàn)證,假定id為數(shù)字集合,自己正則RegExp判斷有效性,pattern為^\d+(,\d+)*$
end if
rows=request.Form("name").count'提交的數(shù)據(jù)行數(shù)據(jù),包括添加/修改的
for i=1 to rows'遍歷每行數(shù)據(jù)
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為數(shù)字加isnumeric判斷
response.Write "要修改數(shù)據(jù)行:"&id&"|"&name&"|"&sex&"|"&age&"|"&addr&"<br>"
'修改操作
else'添加操作
response.Write "要添加數(shù)據(jù)行:"&name&"|"&sex&"|"&age&"|"&addr&"<br>"
'添加操作
end if
next
end if
%>
<form method="post" onsubmit="return check(this)">
<input type="hidden" name="ids" /><!--用于存儲(chǔ)要?jiǎng)h除記錄的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>
<!-------要修改的數(shù)據(jù),自己讀取數(shù)據(jù)庫(kù)生成,<input type="hidden" name="id" value=""/>存儲(chǔ)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>
<!-------要修改的數(shù)據(jù)示例結(jié)束-------->
<tr><td colspan="5" align="center"><input type="submit" value="提交"/> <input type="button" value="添加新數(shù)據(jù)行" onclick="addRow()" /></td></tr>
</table>
</form>
<script type="text/javascript">
function removeRow(btn){
if (confirm('確認(rèn)刪除?!')) {
var tr=btn.parentNode.parentNode;
var id = btn.nextSibling;//注意刪除按鈕和id這個(gè)hidden控件之間不要有空格,要不nextSibling在標(biāo)準(zhǔn)瀏覽器下是空白節(jié)點(diǎn)
if (id.value != '') {//刪除是存在的行而不是新增的,則id存儲(chǔ)到ids中
btn.form.ids.value += (btn.form.ids.value == '' ? '' : ',') + id.value;
}
tr.parentNode.removeChild(tr);
}
}
function addRow() {
var tb = document.getElementById('tb'), tr = tb.insertRow(tb.rows.length - 1),td=tr.insertCell(0);
td.innerHTML = '<input type="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" />';//新增數(shù)據(jù)行id為空
}
function check(f) {
var tb = document.getElementById('tb'), ipts;
for (var i = 1, j = tb.rows.length - 1; i < j; i++) {//輸入驗(yàn)證,去掉第一行表頭和最后一行操作
ipts = tb.rows[i].getElementsByTagName('input');
if (ipts[0].value == '') { alert('請(qǐng)輸入姓名!'); ipts[0].focus(); return false; }
if (ipts[1].value == '') { alert('請(qǐng)輸入性別!'); ipts[1].focus(); return false; }
if (ipts[2].value == '') { alert('請(qǐng)輸入年齡!'); ipts[2].focus(); return false; }
if (ipts[3].value == '') { alert('請(qǐng)輸入地址!'); ipts[3].focus(); return false; }
}
}
</script>
上一篇:詳解ABP框架中的日志管理和設(shè)置管理的基本配置
欄 目:ASP編程
本文標(biāo)題:asp批量添加修改刪除操作示例代碼
本文地址:http://www.jygsgssxh.com/a1/ASPbiancheng/11351.html
您可能感興趣的文章
- 01-11ASP新手必備的基礎(chǔ)知識(shí)
- 01-11ASP實(shí)現(xiàn)加法驗(yàn)證碼
- 01-11asp服務(wù)器如何搭建
- 01-11ASP腳本組件實(shí)現(xiàn)服務(wù)器重啟
- 01-11ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享
- 01-11ASP實(shí)現(xiàn)類(lèi)似hashMap功能的類(lèi)
- 01-11ASP編碼必備的8條原則
- 01-11解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)題
- 01-11ASP程序中常用的腳本語(yǔ)言
- 01-11ASP中用select case代替其他語(yǔ)言中的switch case, default用case else


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 01-11ASP實(shí)現(xiàn)加法驗(yàn)證碼
- 01-11ASP新手必備的基礎(chǔ)知識(shí)
- 01-11ASP腳本組件實(shí)現(xiàn)服務(wù)器重啟
- 01-11asp服務(wù)器如何搭建
- 01-11ASP實(shí)現(xiàn)類(lèi)似hashMap功能的類(lèi)
- 01-11ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享
- 01-11解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問(wèn)
- 01-11ASP編碼必備的8條原則
- 01-11ASP中用select case代替其他語(yǔ)言中的sw
- 01-11ASP程序中常用的腳本語(yǔ)言
隨機(jī)閱讀
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 04-02jquery與jsp,用jquery
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載


