错了,是利用setAttribute()来添加。
解决方案 »
- easyui 中datagrid 如何双击 全码谢谢
- 点radio怎么用javascript控制div层,急求,在线等高手解答
- jsp插入中文到MySql乱码问题解决总结
- 如何通过单选按钮改变表单?
- html调用外部js文件函数问题
- 蛙蛙请教:动态拼接表格问题
- 怎样使下拉框中的<option>aaa</option>居中显示?其它几项很长,第一项aaa靠在左侧太难看了!能否让aaa居中?
- 有关对象不存在的问题.
- 如何做首页弹出很大的广告条,过几秒后自动消失?
- iframe高度自适应,怎么试都不行啊
- 求助!我用Fireworks制作的弹出菜单,在框架结构中只能显示菜单所在框架部分,而在其他框架却不显示,也就是菜单不完整显示。有什么办法
- 滚动的stop!一定给分.
input_node.setAttribute("onclick","remove_row(this.form)")
或
input_node.onclick="remove_row(this.form)"
你这里这句话已经运行了remove_row(this.form)
难道是我的remove_row()函数出错了?那也不会在不加“”时自动删除!
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>用户ID</title>
<style>
<!--
td { font-size: 9pt }
-->
</style>
<script language="javascript" type="text/javascript" src="users_records.js">
</script><script language="javascript" type="text/javascript">
<!--var new_rows = 1
var table_rowsfunction insert_row(current_form) {
// Get the reference row number
var reference_row = 1
// Get the table body
var tbody_node = document.getElementById("tablebody").childNodes[0]
//alert(tbody_node.outerHTML)
// Get the reference row element
var reference_node = tbody_node.childNodes[0]
//alert(reference_node.outerHTML) // Create the new <tr> element
var new_tr_node = document.createElement("tr")
var inserted_node = tbody_node.insertBefore(new_tr_node, reference_node)
// Get the number of columns
var table_columns = 6
//alert(table_columns)
/*
var td_node = document.createElement("td")
inserted_node.appendChild(td_node)
var input_node = document.createElement("input")
input_node.type = "text"
*/ // Loop to add all the <td> elements (columns) in the inserted row
for (var col_counter = 1; col_counter <= table_columns; col_counter++) {
var td_node = document.createElement("td")
inserted_node.appendChild(td_node)
// Add input(type=text) to the current cell
var input_node = document.createElement("input")
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true if(col_counter <= 2){
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true
input_node.size = "20"
//input_node.value = "T" + new_rows + "_" + col_counter
}else if(col_counter >2 && col_counter <5){
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true
input_node.size = "8"
}else if (col_counter == 5){
input_node.type = "button"
input_node.name = "B" + new_rows + "_" + col_counter
input_node.disabled = false
input_node.value = "添加"
}else{
input_node.type = "button"
input_node.name = "B" + new_rows + "_" + col_counter
input_node.disabled = false
input_node.value = "删除此行"
input_node.setAttribute("onclick", remove_row(this.form))
//input_node.onclick = "remove_row(this.form)"
//input_node.mousedown = remove_row(this.form)
}
// Add a text node to the current cell
//var input_node = document.createTextNode("New Row " + new_rows + " Col " + col_counter)
td_node.appendChild(input_node)
}
// Increment the total number of new and existing rows
new_rows++
table_rows++}function remove_row(current_form){
alert("running!")
// Get the table body
var tbody_node = document.getElementById("tablebody").childNodes[0]
alert(tbody_node.outerHTML)
// Get the row number that will be cloned
var row_number = 1
// Get the row element to be deleted
var row_node = tbody_node.childNodes[0]
// Remove it
tbody_node.removeChild(row_node)
// Decrement the total number of table rows
table_rows--
}-->
</script>
</head><body>
<form method="POST" action="--WEBBOT-SELF--" name="username">
<table border="1" width="58%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" height="48">
<script language="javascript" type="text/javascript">
<!-- // Write the table headers
document.writeln('<tr>')
document.writeln('<td width="15%" align="center" bgcolor="#E6E6E6" height="16">用户ID</td>')
document.writeln('<td width="24%" align="center" bgcolor="#E6E6E6" height="16">用户名</td>')
document.writeln('<td width="7%" align="center" bgcolor="#E6E6E6" height="16">性别</td>')
document.writeln('<td width="8%" align="center" bgcolor="#E6E6E6" height="16">年龄</td>')
document.writeln('<td width="34%" align="center" bgcolor="#E6E6E6" height="16">添加</td>')
document.writeln('<td width="21%" align="center" bgcolor="#E6E6E6" height="16">删除</td>')
document.writeln('<\/tr>')
-->
</script>
</table>
<table border="1" width="58%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" height="48" id="tablebody">
<tr>
<td width="15%" height="28"><input type="text" name="T1" size="20"></td>
<td width="24%" height="28"><input type="text" name="T2" size="20"></td>
<td width="7%" height="28"><input type="text" name="T3" size="8"></td>
<td width="8%" height="28"><input type="text" name="T4" size="8"></td>
<td width="34%" height="28"><input type="button" value="添加" name="B5"></td>
<td width="21%" height="28"><input type="button" value="删除此行" name="B4"></td>
</tr>
</table>
<p><input type="button" value="增加一行" name="B3" onclick="insert_row(this.form)">
<input type="submit" value="提交" name="B1"><input type="button" value="平均年龄" name="B6"><input type="text" name="T5" size="7">岁</p>
</form>
</body>
</html>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>用户ID</title>
<style>
<!--
td { font-size: 9pt }
-->
</style>
<script language="javascript" type="text/javascript" src="users_records.js">
</script><script language="javascript" type="text/javascript">
<!--var new_rows = 1
var table_rowsfunction insert_row(current_form) {
// Get the reference row number
var reference_row = 1
// Get the table body
var tbody_node = document.getElementById("tablebody").childNodes[0]
//alert(tbody_node.outerHTML)
// Get the reference row element
var reference_node = tbody_node.childNodes[0]
//alert(reference_node.outerHTML) // Create the new <tr> element
var new_tr_node = document.createElement("tr")
var inserted_node = tbody_node.insertBefore(new_tr_node, reference_node)
// Get the number of columns
var table_columns = 6
//alert(table_columns)
/*
var td_node = document.createElement("td")
inserted_node.appendChild(td_node)
var input_node = document.createElement("input")
input_node.type = "text"
*/ // Loop to add all the <td> elements (columns) in the inserted row
for (var col_counter = 1; col_counter <= table_columns; col_counter++) {
var td_node = document.createElement("td")
inserted_node.appendChild(td_node)
// Add input(type=text) to the current cell
var input_node = document.createElement("input")
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true if(col_counter <= 2){
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true
input_node.size = "20"
//input_node.value = "T" + new_rows + "_" + col_counter
}else if(col_counter >2 && col_counter <5){
input_node.type = "text"
input_node.name = "T" + new_rows + "_" + col_counter
input_node.disabled = true
input_node.size = "8"
}else if (col_counter == 5){
input_node.type = "button"
input_node.name = "B" + new_rows + "_" + col_counter
input_node.disabled = false
input_node.value = "添加"
}else{
input_node.type = "button"
input_node.name = "B" + new_rows + "_" + col_counter
input_node.disabled = false
input_node.value = "删除此行"
//input_node.setAttribute("onclick", remove_row(this.form))
input_node.onclick = remove_row
//input_node.mousedown = remove_row(this.form)
}
// Add a text node to the current cell
//var input_node = document.createTextNode("New Row " + new_rows + " Col " + col_counter)
td_node.appendChild(input_node)
}
// Increment the total number of new and existing rows
new_rows++
table_rows++}function remove_row(){
alert("running!")
// Get the table body
var tbody_node = document.getElementById("tablebody").childNodes[0]
alert(tbody_node.outerHTML)
// Get the row number that will be cloned
var row_number = 1
// Get the row element to be deleted
var row_node = tbody_node.childNodes[0]
// Remove it
tbody_node.removeChild(row_node)
// Decrement the total number of table rows
table_rows--
}-->
</script>
</head><body>
<form method="POST" action="--WEBBOT-SELF--" name="username">
<table border="1" width="58%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" height="48">
<script language="javascript" type="text/javascript">
<!-- // Write the table headers
document.writeln('<tr>')
document.writeln('<td width="15%" align="center" bgcolor="#E6E6E6" height="16">用户ID</td>')
document.writeln('<td width="24%" align="center" bgcolor="#E6E6E6" height="16">用户名</td>')
document.writeln('<td width="7%" align="center" bgcolor="#E6E6E6" height="16">性别</td>')
document.writeln('<td width="8%" align="center" bgcolor="#E6E6E6" height="16">年龄</td>')
document.writeln('<td width="34%" align="center" bgcolor="#E6E6E6" height="16">添加</td>')
document.writeln('<td width="21%" align="center" bgcolor="#E6E6E6" height="16">删除</td>')
document.writeln('<\/tr>')
-->
</script>
</table>
<table border="1" width="58%" bordercolor="#000000" cellspacing="0" cellpadding="0" bordercolordark="#FFFFFF" height="48" id="tablebody">
<tr>
<td width="15%" height="28"><input type="text" name="T1" value=100 size="20"></td>
<td width="24%" height="28"><input type="text" name="T2" size="20"></td>
<td width="7%" height="28"><input type="text" name="T3" size="8"></td>
<td width="8%" height="28"><input type="text" name="T4" size="8"></td>
<td width="34%" height="28"><input type="button" value="添加" name="B5"></td>
<td width="21%" height="28"><input type="button" value="删除此行" onclick=remove_row() name="B4"></td>
</tr>
</table>
<p><input type="button" value="增加一行" name="B3" onclick="insert_row(this.form)">
<input type="submit" value="提交" name="B1"><input type="button" value="平均年龄" name="B6"><input type="text" name="T5" size="7">岁</p>
</form>
</body>
</html>