请教:为何不能删除指定的行 用div吧,每一个div给个id,删除的时候直接删除对应id的就可以了. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 那好吧function addbb(rows){ return '<input type="text" name="email[]" id="bb" /><input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />'; }function removeTextBox(worksId,rowid){ var a = 0; if(rowid!==0){ a = rowid; }else{ a = textNumber; } alert(a); var works = document.getElementById(worksId); if(a>1){ works.deleteRow(a-2); a--; } }<input type="button" value="删除一行" onclick="removeTextBox('works',0)" /> removeTextBox 里面的你自己再根据已删除的行数,改一下就差不多了 没读一行数据标识一个id,删除的时候remove不就可以了. [Quote=引用 6 楼 enasp 的回复:]引用 4 楼 cheryc666 的回复:那好吧 function addbb(rows){ return ' <input type="text" name="email[]" id="bb" /> <input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />'; ---我是需要删除当前行,而不是从后面删除,比如当前行号为4,我点击4行后面的删除按钮就把第四行删除了,5行,6行以此类推} function removeTextBox(worksId,rowid){ var a = 0; if(rowid!==0){ a = rowid; }else{ a = textNumber; } alert(a); ---这里打印出来的是最后一行的行号, var works = document.getElementById(worksId); if(a>1){ works.deleteRow(a-2); a--; } } <html> <head> <title>动态增加文本框 </title> <link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-cold-1.css" title="win2k-cold-1" /> <script type="text/javascript" src="js/calendar.js"> </script> <script type="text/javascript" src="js/calendar-zh.js"> </script> <script type="text/javascript" src="js/calendar-setup.js"> </script> <script type="text/javascript"> <!-- var textNumber = 1; function addTitle(rows){ return "提醒" + (rows+1) + ":"; } function del() { document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex); } ------用这个也不行 //function addaa(rows){ //return rows; // return " <input type=\"text\" name=\"aa[]\" size=\"20\" value=\"\" id=\"begin_date_b" + rows + "\"> <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">"; //} function addaa(rows){ //return rows; return " <input type=\"+text\" name=\"tt[]" + rows + "\" id=\"begin_date_b" + rows + "\" />" + " <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">"; } function addbb(rows){ //return rows return " <input type=\"+text\" name=\"bb[]" + rows + "\" id=\"bb" + rows + "\" />"+" <input type=\"reset\" value=\"删除\" onclick=\"removeTextBox('works')" + rows + "\">"; } -----这个地方调用原函数删除每行----调用del()也不能删除 function addtt(rows){ //return rows; return " <input type=\"+text\" name=\"content[]" + rows + "\" id=\"tt" + rows + "\" />"; } function addTextBox(worksId){ var works = document.getElementById(worksId); var newRow = works.insertRow(-1); var newCell = newRow.insertCell(0); newCell.innerHTML = addTitle(textNumber); newCell = newRow.insertCell(1); newCell.innerHTML = addtt(textNumber); newCell = newRow.insertCell(2); newCell.innerHTML = addaa(textNumber); newCell = newRow.insertCell(3); newCell.innerHTML = addbb(textNumber); textNumber++; } function removeTextBox(worksId){ var works = document.getElementById(worksId); if(textNumber>1){ works.deleteRow(textNumber-2); textNumber--; ---这个函数只能从后往前删除,我现在需要删除指定的当前行,比如当前行号为4,我点击4行后面的删除按钮就把第四行删除了,5行,6行以此类推 } } //--> </script> <style type="text/css"> <!-- label { display:block; margin:.25em 0em; } --> </style> </head> <body> <form method="POST" action="ttcrm.php"> <table> <tr> <td>提醒1: </td> <td> <input type="text" name="tt[]" id="tt" /> </td> <td> <input type="text" name="aa[]" id="begin_date_b"> <input type="reset" value="..." onclick="return showCalendar('begin_date_b', 'y-m-d');"> </td> <td> <input type="text" name="bb[]" id="bb" /> </td> </label> </tr> <table id="works"> </table> <p> <input type="button" value="增加一行" onclick="addTextBox('works')" /> <input type="button" value="删除一行" onclick="removeTextBox('works')" /> <p> <input type="Submit" value="提交保存" /> </p> </form> </body> </html> <html> <head> <title>动态增加文本框 </title> <script type="text/javascript"> <!-- var textNumber = 1; var delNumber=0; var textarr = new Array(); function addTitle(rows){ return "提醒" + (rows+1) + ":"; } function del() { document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex); } function addaa(rows){ //return rows; textarr[textarr.length] = rows+1; return " <input type=\"+text\" name=\"tt[]" + rows + "\" id=\"begin_date_b" + rows + "\" />" + " <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">"; } function addbb(rows){ return ' <input type="text" name="email[]" id="bb" /> <input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />'; } function addtt(rows){ //return rows; return " <input type=\"+text\" name=\"content[]" + rows + "\" id=\"tt" + rows + "\" />"; } function addTextBox(worksId){ var works = document.getElementById(worksId); var newRow = works.insertRow(-1); var newCell = newRow.insertCell(0); newCell.innerHTML = addTitle(textNumber); newCell = newRow.insertCell(1); newCell.innerHTML = addtt(textNumber); newCell = newRow.insertCell(2); newCell.innerHTML = addaa(textNumber); newCell = newRow.insertCell(3); newCell.innerHTML = addbb(textNumber); textNumber++; } function removeTextBox(worksId,rowid){ var a = 0; if(rowid!==0){ a = rowid+1; var b=0; for(var i=0;i<textarr.length;i++) { if(a==textarr[i]){ b=i; textarr.splice(i,1); break; } } a= b+2; }else{ a = textNumber; } var works = document.getElementById(worksId); if(a>1){ works.deleteRow(a-2); } }//--> </script> <style type="text/css"> <!-- label { display:block; margin:.25em 0em; } --> </style> </head> <body> <form method="POST" action="ttcrm.php"> <table> <tr> <td>提醒1: </td> <td> <input type="text" name="tt[]" id="tt" /> </td> <td> <input type="text" name="aa[]" id="begin_date_b"> <input type="reset" value="..." onclick="return showCalendar('begin_date_b', 'y-m-d');"> </td> <td> <input type="text" name="bb[]" id="bb" /> </td> </label> </tr> <table id="works"> </table> <p> <input type="button" value="增加一行" onclick="addTextBox('works')" /> <input type="button" value="删除一行" onclick="removeTextBox('works',0)" /> <p> <input type="Submit" value="提交保存" /> </p> </form> </body> </html>无语 function addbb(rows){ //return rows return " <input type=\"+text\" name=\"bb[]" + rows + "\" id=\"bb" + rows + "\" />"+" <input type=\"reset\" value=\"删除\" onclick=\"removeTextBox('works')" + rows + "\">"; } -----这个地方调用原函数删除每行----调用del()也不能删除 大哥你拿我的代码全部copy了去试一下,哪里的标签需要改成你要用的,再改下好了. 首先非常感谢你,但是COPY完运行,什么都不能用了,增加动态框都不行了 我的是把你的那些js文件去掉了,单独以html运行这个是没问题的,其实就是做了个数组记录,删除的时候计算下当前点击的是第几个row. php如何获取远程服务器的时间啊 Mysql插入大量数据出错。。。 ACityName1=%u4e39%u4e1c 这个等号后面的是什么啊? 不喜欢新版的CSDN·又搞一堆的弱智游戏! PHP程序员【应聘】--北京 网站怎么论坛整合! 多表查询同一字段 请问PHP中的eregi如何匹配汉字 怎样避免这样的信息出现,我希望是自动再次显示当前页 php学着学着迷糊了,请教一下 关于禁止访问某个目录的htaccess文件 求一个PHP调用,不知道是难在逻辑上,还是调用语句错了
function addbb(rows){
return '<input type="text" name="email[]" id="bb" /><input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />';
}
function removeTextBox(worksId,rowid){
var a = 0;
if(rowid!==0){
a = rowid;
}else{
a = textNumber;
}
alert(a);
var works = document.getElementById(worksId);
if(a>1){
works.deleteRow(a-2);
a--;
}
}
<input type="button" value="删除一行" onclick="removeTextBox('works',0)" />
removeTextBox 里面的你自己再根据已删除的行数,改一下就差不多了
引用 4 楼 cheryc666 的回复:
那好吧
function addbb(rows){
return ' <input type="text" name="email[]" id="bb" /> <input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />'; ---我是需要删除当前行,而不是从后面删除,比如当前行号为4,我点击4行后面的删除按钮就把第四行删除了,5行,6行以此类推
}
function removeTextBox(worksId,rowid){
var a = 0;
if(rowid!==0){
a = rowid;
}else{
a = textNumber;
}
alert(a); ---这里打印出来的是最后一行的行号,
var works = document.getElementById(worksId);
if(a>1){
works.deleteRow(a-2);
a--;
}
}
<head>
<title>动态增加文本框 </title>
<link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-cold-1.css" title="win2k-cold-1" />
<script type="text/javascript" src="js/calendar.js"> </script>
<script type="text/javascript" src="js/calendar-zh.js"> </script> <script type="text/javascript" src="js/calendar-setup.js"> </script>
<script type="text/javascript">
<!--
var textNumber = 1;
function addTitle(rows){
return "提醒" + (rows+1) + ":";
}
function del()
{
document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex);
} ------用这个也不行
//function addaa(rows){
//return rows;
// return " <input type=\"text\" name=\"aa[]\" size=\"20\" value=\"\" id=\"begin_date_b" + rows + "\"> <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">";
//}
function addaa(rows){
//return rows;
return " <input type=\"+text\" name=\"tt[]" + rows + "\" id=\"begin_date_b" + rows + "\" />" + " <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">";
}
function addbb(rows){
//return rows
return " <input type=\"+text\" name=\"bb[]" + rows + "\" id=\"bb" + rows + "\" />"+" <input type=\"reset\" value=\"删除\" onclick=\"removeTextBox('works')" + rows + "\">"; } -----这个地方调用原函数删除每行----调用del()也不能删除
function addtt(rows){
//return rows;
return " <input type=\"+text\" name=\"content[]" + rows + "\" id=\"tt" + rows + "\" />";
}
function addTextBox(worksId){
var works = document.getElementById(worksId);
var newRow = works.insertRow(-1);
var newCell = newRow.insertCell(0);
newCell.innerHTML = addTitle(textNumber);
newCell = newRow.insertCell(1);
newCell.innerHTML = addtt(textNumber);
newCell = newRow.insertCell(2);
newCell.innerHTML = addaa(textNumber);
newCell = newRow.insertCell(3);
newCell.innerHTML = addbb(textNumber);
textNumber++;
}
function removeTextBox(worksId){
var works = document.getElementById(worksId);
if(textNumber>1){
works.deleteRow(textNumber-2);
textNumber--; ---这个函数只能从后往前删除,我现在需要删除指定的当前行,比如当前行号为4,我点击4行后面的删除按钮就把第四行删除了,5行,6行以此类推
}
}
//-->
</script>
<style type="text/css">
<!--
label {
display:block;
margin:.25em 0em;
}
-->
</style>
</head>
<body> <form method="POST" action="ttcrm.php">
<table>
<tr> <td>提醒1: </td> <td> <input type="text" name="tt[]" id="tt" /> </td>
<td> <input type="text" name="aa[]" id="begin_date_b"> <input type="reset" value="..." onclick="return showCalendar('begin_date_b', 'y-m-d');"> </td>
<td> <input type="text" name="bb[]" id="bb" /> </td> </label>
</tr>
<table id="works">
</table>
<p>
<input type="button" value="增加一行" onclick="addTextBox('works')" />
<input type="button" value="删除一行" onclick="removeTextBox('works')" />
<p> <input type="Submit" value="提交保存" /> </p>
</form> </body>
</html>
<html>
<head>
<title>动态增加文本框 </title>
<script type="text/javascript">
<!--
var textNumber = 1;
var delNumber=0;
var textarr = new Array();
function addTitle(rows){
return "提醒" + (rows+1) + ":";
}
function del()
{
document.all.test.deleteRow(window.event.srcElement.parentElement.parentElement.rowIndex);
}
function addaa(rows){
//return rows;
textarr[textarr.length] = rows+1;
return " <input type=\"+text\" name=\"tt[]" + rows + "\" id=\"begin_date_b" + rows + "\" />" + " <input type=\"reset\" value=\"...\" onclick=\"return showCalendar('begin_date_b" + rows + "', 'y-m-d');\">";
}
function addbb(rows){
return ' <input type="text" name="email[]" id="bb" /> <input type="button" value="删除" onclick="removeTextBox(\'works\','+rows+')" />';
}
function addtt(rows){
//return rows;
return " <input type=\"+text\" name=\"content[]" + rows + "\" id=\"tt" + rows + "\" />";
}
function addTextBox(worksId){
var works = document.getElementById(worksId);
var newRow = works.insertRow(-1);
var newCell = newRow.insertCell(0);
newCell.innerHTML = addTitle(textNumber);
newCell = newRow.insertCell(1);
newCell.innerHTML = addtt(textNumber);
newCell = newRow.insertCell(2);
newCell.innerHTML = addaa(textNumber);
newCell = newRow.insertCell(3);
newCell.innerHTML = addbb(textNumber);
textNumber++;
}
function removeTextBox(worksId,rowid){
var a = 0;
if(rowid!==0){
a = rowid+1;
var b=0;
for(var i=0;i<textarr.length;i++)
{
if(a==textarr[i]){
b=i;
textarr.splice(i,1);
break;
}
}
a= b+2;
}else{
a = textNumber;
}
var works = document.getElementById(worksId);
if(a>1){
works.deleteRow(a-2);
}
}
//-->
</script>
<style type="text/css">
<!--
label {
display:block;
margin:.25em 0em;
}
-->
</style>
</head>
<body> <form method="POST" action="ttcrm.php">
<table>
<tr> <td>提醒1: </td> <td> <input type="text" name="tt[]" id="tt" /> </td>
<td> <input type="text" name="aa[]" id="begin_date_b"> <input type="reset" value="..." onclick="return showCalendar('begin_date_b', 'y-m-d');"> </td>
<td> <input type="text" name="bb[]" id="bb" /> </td> </label>
</tr>
<table id="works">
</table>
<p>
<input type="button" value="增加一行" onclick="addTextBox('works')" />
<input type="button" value="删除一行" onclick="removeTextBox('works',0)" />
<p> <input type="Submit" value="提交保存" /> </p>
</form> </body>
</html>无语
//return rows
return " <input type=\"+text\" name=\"bb[]" + rows + "\" id=\"bb" + rows + "\" />"+" <input type=\"reset\" value=\"删除\" onclick=\"removeTextBox('works')" + rows + "\">"; } -----这个地方调用原函数删除每行----调用del()也不能删除
首先非常感谢你,但是COPY完运行,什么都不能用了,增加动态框都不行了