濮阳杆衣贸易有限公司

主頁 > 知識庫 > asp批量添加修改刪除操作示例代碼

asp批量添加修改刪除操作示例代碼

熱門標(biāo)簽:微信地圖標(biāo)注有什么用 不封卡外呼系統(tǒng)一般多少錢 重慶外呼電銷系統(tǒng)費(fèi)用 電銷機(jī)器人一個多少錢 地圖標(biāo)注不完整被罰款 鄭州語音電銷機(jī)器人官網(wǎng) 北京大興區(qū)地圖標(biāo)注 濰坊呼叫中心外呼系統(tǒng)供應(yīng)商 地圖標(biāo)注中心多少錢注冊

核心代碼:

title>asp批量添加修改刪除操作示例/title>
%
if request.Form("op")="update" then'表單提交
 ids=request.Form("ids")
 if ids>"" then
  response.Write "要刪除的數(shù)據(jù)id集合:"ids"br>"
  '=========數(shù)據(jù)庫刪除操作 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" />!--用于存儲要刪除記錄的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ù)庫生成,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>
!-------要修改的數(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這個hidden控件之間不要有空格,要不nextSibling在標(biāo)準(zhǔn)瀏覽器下是空白節(jié)點(diǎn)
      if (id.value != '') {//刪除是存在的行而不是新增的,則id存儲到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('請輸入姓名!'); 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>

標(biāo)簽:汕頭 唐山 攀枝花 撫州 鶴崗 海南 佛山 揭陽

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp批量添加修改刪除操作示例代碼》,本文關(guān)鍵詞  asp,批量,添加,修改,刪除,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp批量添加修改刪除操作示例代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp批量添加修改刪除操作示例代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    韩城市| 东山县| 墨脱县| 博湖县| 小金县| 河西区| 邢台市| 海门市| 南靖县| 汝城县| 新闻| 定安县| 乌审旗| 吉安市| 建平县| 攀枝花市| 永兴县| 天峻县| 开原市| 广丰县| 泾源县| 张家口市| 五大连池市| 肥乡县| 松溪县| 海宁市| 通许县| 孙吴县| 广昌县| 正蓝旗| 孟连| 江源县| 庄河市| 庆云县| 荆州市| 广州市| 德格县| 定远县| 子洲县| 邹城市| 溧水县|