六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 24|回复: 0

js动态添加和删除行

[复制链接]

升级  94.67%

52

主题

52

主题

52

主题

秀才

Rank: 2

积分
192
 楼主| 发表于 2013-1-29 09:02:24 | 显示全部楼层 |阅读模式
<style>.field {font-family: "MS UI Gothic";font-size: 12px;height: 17px;border: 1px solid #F00000;readonly: false;}.tableLightLine {height: 20;background-color: #FFFFFF;font-family: "MS UI Gothic";font-size: 12px;color: #000000;}.tableDarkLine {height: 20;background-color: #F3F3F3;font-family: "MS UI Gothic";font-size: 12px;color: #000000;}</style><script language="javascript" type="text/javascript">function onAdd(tblId) {var rowLen = tblId.rows.length;var addedCount = 0;if (rowLen > 0) {if (tblId.rows[rowLen -1].all['itemChkedAdded']) {addedCount = tblId.rows[rowLen - 1].all['itemChkedAdded'].value;}}if (addedCount == "") {addedCount = 0;}var addCountC = parseInt(addedCount);addCountC++;var trClassName = "";if (tblId.rows.length % 2 == 0) {trClassName = "tableLightLine";;} else {trClassName = "tableDarkLine";}var rowId = tblId.insertRow();rowId.className = trClassName;rowId.align = "center";rowId.style.Height = "22";var cellId = rowId.insertCell();cellId.width = "25";cellId.align = "center";var innerHTML1 = "";innerHTML1 = innerHTML1 + '<input type="checkbox" name="itemChkedAdded" id="itemChkedAdded" value="' + String(addCountC) + '" />';innerHTML1 = innerHTML1 + '<input type="hidden" name="itemCdedAdded" id="itemCdedAdded" value="' + String(addCountC) + '" />';cellId.innerHTML = innerHTML1;var cellId2 = rowId.insertCell();cellId2.width = "300";cellId2.align = "left";var innerHTML2 = "";innerHTML2 = '<input type="text" name="itemNameAdded" id="itemNameAdded" class="field" size="27" maxlength="40" style="width:299px;" />';cellId2.innerHTML = innerHTML2;var cellId3 = rowId.insertCell();cellId3.width = "125";cellId3.align = "right";var innerHTML3 = "<input name=\"diaItemPriceAdded\" id=\"diaItemPriceAdded\" " + "type=\"text\" class=\"field\" style=\"text-align:right;ime-mode:disabled;\" " + "size='22' "+ "maxlength=\"11\">";cellId3.innerHTML = innerHTML3;}function onDelete(tblId, checkBoxAddedId) {var checked = false;for (var i = 0; i < tblId.rows.length; i++) {if (tblId.rows[i].all[checkBoxAddedId].checked) {checked = true;tblId.deleteRow(i);i--;}}var addCount = 0;for (var i = 0; i < tblId.rows.length; i++) {if (i % 2 == 0) {tblId.rows[i].className = "tableLightLine";} else {tblId.rows[i].className = "tableDarkLine";}if (tblId.rows[i].all[checkBoxAddedId]) {tblId.rows[i].all[checkBoxAddedId].value = String(addCount);tblId.rows[i].all['itemCdedAdded'].value = String(addCount);addCount++;}}if (!checked) {alert("请选择一行");}}</script><input type="button" name="btnAdd" id="btnAdd" value="追加"  /><input type="button" name="btnDelete" id="btnDelete" value="删除"  /><table width="600" border="0" align="left" id="testTblId" style="table-layout: fixed"></table>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表