国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Js實現動態添加刪除Table行示例

2019-11-20 20:49:54
字體:
來源:轉載
供稿:網友
最近做項目遇到要動態添加、刪除表格行的操作,實現如下

html代碼
復制代碼 代碼如下:

<table cellpadding="0" cellspacing="0" border="1" style="margin:auto; width:96%;" id="LearnInfoItem">
<tr >
<td colspan="8" bgcolor="#96E0E2" style="height:30px;" ><h3 style="text-align:center; margin:0;">主要學習簡歷</h3></td>
</tr>
<tr id="tr1">
<td class="tdStyle2">起訖時間 </td>

<td class="tdStyle2">畢業院校</td>

<td class="tdStyle2">所學專業</td>

<td class="tdStyle2">學制</td>

<td class="tdStyle2">學位</td>

<td class="tdStyle2">學習方式</td>

<td class="tdStyle2">文化程度</td>

<td class="tdStyle2">
<input type="button" name="LearnAdd" value="添加" onclick="LearnAddSignRow()" />
<input name='LearnTRLastIndex' type='hidden' id='LearnTRLastIndex' value="1" />
</td>

</tr>
</table>

javascript代碼:
復制代碼 代碼如下:

<script language="javascript" type="text/javascript">// Example: obj = findObj("image1");

function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{
theDoc = parent.frames[theObj.substring(p+1)].document;
theObj = theObj.substring(0,p);
}
if(!(foundObj = theDoc[theObj]) && theDoc.all)
foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById)
foundObj = document.getElementById(theObj);
return foundObj;
}


//添加一行學習簡歷
function LearnAddSignRow(){ //讀取最后一行的行號,存放在LearnTRLastIndex文本框中
var LearnTRLastIndex = findObj("LearnTRLastIndex",document);
var rowID = parseInt(LearnTRLastIndex.value);

var signFrame = findObj("LearnInfoItem",document);
//添加行
var newTR = signFrame.insertRow(signFrame.rows.length);
newTR.id = "LearnItem" + rowID;

//添加列:起訖時間
var newNameTD=newTR.insertCell(0);
//添加列內容
newNameTD.innerHTML = "<input name='txtLearnStartDate" + rowID + "' id='txtLearnStartDate" + rowID + "' type='text' class='inputStyle' />";

//添加列:畢業院校
var newNameTD=newTR.insertCell(1);
//添加列內容
newNameTD.innerHTML = "<input name='txtName" + rowID + "' id='txtName" + rowID + "' type='text' class='inputStyle' />";

//添加列:所學專業
var newEmailTD=newTR.insertCell(2);
//添加列內容
newEmailTD.innerHTML = "<input name='txtEMail" + rowID + "' id='txtEmail" + rowID + "' type='text' class='inputStyle' />";

//添加列:學制
var newTelTD=newTR.insertCell(3);
//添加列內容
newTelTD.innerHTML = "<input name='txtTel" + rowID + "' id='txtTel" + rowID + "' type='text' class='inputStyle' />";

//添加列:學位
var newMobileTD=newTR.insertCell(4);
//添加列內容
newMobileTD.innerHTML = "<input name='txtMobile" + rowID + "' id='txtMobile" + rowID + "' type='text' class='inputStyle' />";

//添加列:學習方式
var newMobileTD=newTR.insertCell(5);
//添加列內容
newMobileTD.innerHTML = "<input name='txtMobile" + rowID + "' id='txtMobile" + rowID + "' type='text' class='inputStyle' />";

//添加列:文化程度
var newCompanyTD=newTR.insertCell(6);
//添加列內容
newCompanyTD.innerHTML = "<input name='txtCompany" + rowID + "' id='txtCompany" + rowID + "' type='text' class='inputStyle' />";


//添加列:刪除按鈕
var newDeleteTD=newTR.insertCell(7);
//添加列內容
newDeleteTD.innerHTML = "<div align='center'><input id='txtDel" + rowID + "' type='button' value='刪除' onclick=/"LearnDeleteRow('LearnItem" + rowID + "')/" class='inputStyle' /></div>";

//將行號推進下一行
LearnTRLastIndex.value = (rowID + 1).toString() ;
}
//刪除指定行
function LearnDeleteRow(rowid){
var signFrame = findObj("LearnInfoItem",document);
var signItem = findObj(rowid,document);

//獲取將要刪除的行的Index
var rowIndex = signItem.rowIndex;

//刪除指定Index的行
signFrame.deleteRow(rowIndex);

}

}
</script>

實現效果:
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜兴市| 黄石市| 金华市| 西华县| 崇礼县| 桑植县| 石家庄市| 浦江县| 卓尼县| 宣城市| 金平| 新竹县| 宝清县| 东港市| 酒泉市| 平和县| 冷水江市| 杭锦旗| 长汀县| 平乐县| 南康市| 格尔木市| 奎屯市| 孟连| 英吉沙县| 阿鲁科尔沁旗| 博爱县| 平度市| 达州市| 甘洛县| 隆德县| 盖州市| 武穴市| 上饶县| 泸西县| 随州市| 平原县| 巧家县| 乌拉特前旗| 中牟县| 仪陇县|