---
title: "javascript add node"
author: "luogen33"
date: "2011-10-20T00:09:51Z"
tags: []
categories: ["编程语言"]
slug: "javascript-add-node"
draft: false
lastmod: "2011-10-20T00:09:51Z"
id: 1202377
url: "https://luogen33.iteye.com/blog/1202377"
---

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<Script Language="Javascript">
var cGetRow=-99999;
var i=0;
function 
	AddRow() {
		//添加一行
		var newTr = tab1.insertRow(0);
		//添加两列
		var newTd0 = newTr.insertCell(0);
		var newTd1 = newTr.insertCell(0);
		//设置列内容和属性
		newTd0.innerHTML = '<input type=checkbox id="box"+i onClick="GetRow()">';
		newTd1.innerText = '新增加行';
	}

	function DelRow(iIndex) {
		//删除一行
		if (iIndex == -99999)
			alert("系统提示：没有选中行号!");
		else
			tab1.deleteRow(iIndex);
	}

	function GetRow() {
		//获得行索引
		cGetRow = window.event.srcElement.parentElement.parentElement.rowIndex;
		alert(cGetRow)
	}

	function ShowRow() {
		//显示行号
		alert(cGetRow);
	}
</script>
</head>

<body>
<table id="tab1" border=1>
    
</table>

<input type="submit" name="Submit" value="AddRow" onclick="javascript:AddRow();">
<input type="submit" name="Submit" value="DelRow" onclick="javascript:DelRow(cGetRow);">
<input type="submit" name="Submit" value="ShowRow" onclick="javascript:ShowRow();">  
</body>