在表格中的最后一列按回车,表格再增一行;重金啊!

internetibm 2002-10-18 04:36:29
我想在一个表格动态输入:比如
----------------------------
|品名| 单价| 产地 |
-----------------------------
|彩电| 1200| 四川 |
______________________________
当在产地中输入四川,同时品名单价不为空时表格自动增加一行
...全文
84 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
internetibm 2002-10-18
  • 打赏
  • 举报
回复
每一行表示一条记录;我要将这一条条记录写入到数据库中;这个问题解决完就结贴!
internetibm 2002-10-18
  • 打赏
  • 举报
回复
谢谢各位,你们的程序都较为复杂;不知道我能否将表格中的值追加至数据库中!
gq 2002-10-18
  • 打赏
  • 举报
回复
前面理解错误。
下面贴一个能对表格进行操作的,提供给你参考。
*****************************************
<HTML>
<HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE type=text/css>BODY {
BACKGROUND: white; COLOR: black; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableData {
BACKGROUND: white; BORDER-BOTTOM: white 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: white 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataSel {
BACKGROUND: #6090d0; BORDER-BOTTOM: #6090d0 1px dashed; BORDER-LEFT: #6090d0 1px dashed; BORDER-RIGHT: #6090d0 1px dashed; BORDER-TOP: #6090d0 1px dashed; COLOR: white; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataHit {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataOver {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.controlPanel {
BACKGROUND: silver; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.controlPanelMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.delMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.scheduleButtonVisible {
BACKGROUND: silver; BORDER-BOTTOM: gray 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: gray 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: webdings; FONT-SIZE: 12px
}
</STYLE>
<SCRIPT language=javascript>
var modified=0
var currentLine=-1
var line=-1
function lightOn(ln)
{
if (ln==null)
ln=parseInt(event.srcElement.ln,10)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==ln)
line=i
cln=currentLine
oldLine=-1
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==cln)
oldLine=i
if (line==oldLine)
return
//if td <0 then only clear all title
if (line>0)
{
document.all.tdt[line].className="tableDataHit";
document.ecform("medication")[line].className="tableDataHit";
if (oldLine>0)
{
document.all.tdt[oldLine].className="tableData";
document.ecform("medication")[oldLine].className="tableData";
}
currentLine=ln
}
}

function move(direc){
//向下移动direc行,并将移动到的行高亮度显示

if(line+direc<1 || (line+direc)>document.all.tdt.length-1) return;
var temp=document.ecform.medication[line].value;
document.ecform.medication[line].value=document.ecform.medication[line+direc].value;
document.ecform.medication[line+direc].value=temp

line+=direc;
lightOn(line);
}
function delIt()
{
line=parseInt(event.srcElement.ln,10)

if (line>0)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==line)
{
if ( document.ecform.medication[i].value.length>0 )
if (!confirm("Are you sure you want to delete this record?"))
return
PLList.deleteRow(i)
}
}
function modifiedIt(field)
{
// field.value=checkText(field.value);
modified=1
line=parseInt(event.srcElement.ln,10)

if (line>0)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==line)
document.ecform.edit[i].value=1
}
function newHospitalVisit()
{
newRow=PLList.insertRow(PLList.rows.length);
newRow.id="tdt";
newRow.ln=allCount;
newRow.bgColor="#e0e0e0";
newRow.className="tableData";
newRow.onclick=lightOn;

c1=newRow.insertCell(0);
c1.id="delItem";
c1.ln=allCount;
c1.className="scheduleButtonVisible";
c1.onclick=delIt;
c1.onmouseover=mouseOver;
c1.onmouseout=mouseOut;
c1.innerHTML="<input type=hidden name=PLID value=0><input type='hidden' name='edit' value=0>";
c2=newRow.insertCell(1);
c2.ln=allCount;
c2.innerHTML="<input type=text size=58 maxlength=100 name=medication ln="+allCount+" class=tableData onkeyup='modifiedIt()'>"
allCount++
}
function mouseOver()
{
event.srcElement.className="delMouseOver"
}
function mouseOut()
{
event.srcElement.className="scheduleButtonVisible"
}
</SCRIPT>
</HEAD>
<BODY bgColor=white>
<FORM method=post name=ecform>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<DIV id=div1
style="LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 658px">
<TABLE bgColor=silver border=2 borderColorDark=gray borderColorLight=silver
cellPadding=2 cellSpacing=1 cols=1 id=PLList rules=rows width="100%">
<TBODY>
<TR bgColor=#0a6846 id=tdt>
<TH width=80><FONT color=white>删除
<INPUT name=PLID type=hidden>
<INPUT
name=edit type=hidden>
</FONT></TH>
<TH width="559">
<INPUT name=medication type=hidden>
<FONT
color=white>变化表格 </font>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="1">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="1" width="80"><FONT size=2>
<INPUT name=PLID type=hidden
value=54 ln="1">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="1" width="559">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 value="like it?" ln="1">
</TD>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="2">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="2" width="80"><FONT size=2>
<INPUT name=PLID type=hidden
value=55 ln="2">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="2" width="559">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 value="how about it?" ln="2">
</TD>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="3">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="3" width="80"><FONT size=2>
<INPUT name=PLID type=hidden
value=56 ln="3">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="3" width="559">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 ln="3">
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT>
allCount=4
</SCRIPT>


<TABLE align=center border=1 borderColorDark=white borderColorLight=gray
cellPadding=1 cellSpacing=1 class=controlPanel cols=4 rules=all width="100%"
nowrap>
<TBODY>
<TR>
<TD align=middle class=controlPanel onclick=newHospitalVisit()
onmouseout="this.className='controlPanel'"
onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">添加一行</font></TD>
</TR>
<TR>
<TD align=middle class=controlPanel onclick=move(-1)
onmouseout="this.className='controlPanel'"
onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">向上移动</font></TD>
</TR>
<TR>
<TD align=middle class=controlPanel onclick=move(1)
onmouseout="this.className='controlPanel'"
onmouseover="this.className='controlPanelMouseOver'"><font size="2" face="仿宋_GB2312, 楷体_GB2312">向下移动</font></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</FORM>
</BODY>
</HTML>

internetibm 2002-10-18
  • 打赏
  • 举报
回复
你的程序,在品名和单价为空格时也在增加啊!同时需要增加一删除功能
|品名| 单价| 产地 |
-----------------------------
|彩电| 1200| 四川 删除 |
|手机| 1200| 四川 删除 |
同时在鼠标离开输入框时,输入框变成不可见,只显示表格和值;当鼠标移到某一单元格双击时,输入框可见,值可修改!

sallina 2002-10-18
  • 打赏
  • 举报
回复
</HEAD>
<BODY bgColor=white>
<FORM method=post name=ecform>
<META content="MSHTML 5.00.2920.0" name=GENERATOR>
<DIV id=div1
style="LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 658px">
<TABLE bgColor=silver border=2 borderColorDark=gray borderColorLight=silver
cellPadding=2 cellSpacing=1 cols=1 id=PLList rules=rows width="100%">
<TBODY>
<TR bgColor=#0a6846 id=tdt>
<TH width=10><FONT color=white>X
<INPUT name=PLID type=hidden>
<INPUT
name=edit type=hidden>
</FONT></TH>
<TH width="10%">
<INPUT name=date type=hidden>
<FONT color=white>Date </FONT>
<TH width="30%">
<INPUT name=diagnosis type=hidden>
<FONT
color=white>Diagnosis </FONT>
<TH width="60%">
<INPUT name=medication type=hidden>
<FONT
color=white>Medication </font>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="1">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="1"><FONT size=2>
<INPUT name=PLID type=hidden
value=54 ln="1">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="1">
<INPUT class=tableData maxLength=10 name=date
onkeyup=modifiedIt(this) size=10 ln="1">
</TD>
<TD ln="1">
<INPUT class=tableData maxLength=50 name=diagnosis
onkeyup=modifiedIt(this) size=25 value="what do you think of it?"
ln="1">
</TD>
<TD ln="1">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 value="like it?" ln="1">
</TD>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="2">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="2"><FONT size=2>
<INPUT name=PLID type=hidden
value=55 ln="2">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="2">
<INPUT class=tableData maxLength=10 name=date
onkeyup=modifiedIt(this) size=10 value=01/01/1999 ln="2">
</TD>
<TD ln="2">
<INPUT class=tableData maxLength=50 name=diagnosis
onkeyup=modifiedIt(this) size=25 value="it`s a test" ln="2">
</TD>
<TD ln="2">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 value="how about it?" ln="2">
</TD>
</TR>
<TR bgColor=#e0e0e0 class=tableData id=tdt onclick=lightOn() ln="3">
<TD class=scheduleButtonVisible onclick=delIt() onmouseout=mouseOut()
onmouseover=mouseOver() ln="3"><FONT size=2>
<INPUT name=PLID type=hidden
value=56 ln="3">
<INPUT name=edit type=hidden value=0>
</FONT></TD>
<TD ln="3">
<INPUT class=tableData maxLength=10 name=date
onkeyup=modifiedIt(this) size=10 value=02/01/2000 ln="3">
</TD>
<TD ln="3">
<INPUT class=tableData maxLength=50 name=diagnosis
onkeyup=modifiedIt(this) size=25 value="another test" ln="3">
</TD>
<TD ln="3">
<INPUT class=tableData maxLength=100 name=medication
onkeyup=modifiedIt(this) size=58 ln="3">
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT>
allCount=4
</SCRIPT>
<TABLE align=center border=1 borderColorDark=white borderColorLight=gray
cellPadding=1 cellSpacing=1 class=controlPanel cols=4 rules=all width="100%"
nowrap>
<TBODY>
<TR>
<TD align=middle class=controlPanel onclick=newHospitalVisit()
onmouseout="this.className='controlPanel'"
onmouseover="this.className='controlPanelMouseOver'"><FONT size=2>Add a New
Record, click here</FONT></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
</FORM>
</BODY>
</HTML>

sallina 2002-10-18
  • 打赏
  • 举报
回复
<SCRIPT language=javascript>
var modified=0
var currentLine=-1//该变量似乎保存"ln"属性;lightOn函数中line记录实际行数
var line=-1;
function lightOn(ln)
{
if (ln==null)
ln=parseInt(event.srcElement.ln,10)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==ln)
line=i
cln=currentLine
oldLine=-1
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==cln)
oldLine=i
if (line==oldLine)
return
//if td <0 then only clear all title
if (line>0)
{
document.all.tdt[line].className="tableDataHit";
document.ecform("date")[line].className="tableDataHit";
document.ecform("diagnosis")[line].className="tableDataHit";
document.ecform("medication")[line].className="tableDataHit";
if (oldLine>0)
{
document.all.tdt[oldLine].className="tableData";
document.ecform("date")[oldLine].className="tableData";
document.ecform("diagnosis")[oldLine].className="tableData";
document.ecform("medication")[oldLine].className="tableData";
}
currentLine=ln
}
}
function delIt()
{
line=parseInt(event.srcElement.ln,10)

if (line>0)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==line)
{
if (document.ecform.diagnosis[i].value.length>0 || document.ecform.medication[i].value.length>0 || document.ecform.date[i].value.length>0)
if (!confirm("Are you sure you want to delete this record?"))
return
PLList.deleteRow(i)
}
}
function modifiedIt(field)
{
// field.value=checkText(field.value);
modified=1
line=parseInt(event.srcElement.ln,10)

if (line>0)
for (i=1;i<PLList.rows.length;i++)
if (tdt[i].ln==line)
document.ecform.edit[i].value=1
}
function newHospitalVisit()
{
newRow=PLList.insertRow(PLList.rows.length);
newRow.id="tdt";
newRow.ln=allCount;
newRow.bgColor="#e0e0e0";
newRow.className="tableData";
newRow.onclick=lightOn;

c1=newRow.insertCell(0);
c1.id="delItem";
c1.ln=allCount;
c1.className="scheduleButtonVisible";
c1.onclick=delIt;
c1.onmouseover=mouseOver;
c1.onmouseout=mouseOut;
c1.innerHTML="<input type=hidden name=PLID value=0><input type='hidden' name='edit' value=0>";
c2=newRow.insertCell(1);
c2.ln=allCount;
c2.innerHTML="<input type=text size=10 maxlength=10 name=date ln="+allCount+" class=tableData onkeyup='modifiedIt()'>"
c3=newRow.insertCell(2);
c3.ln=allCount;
c3.innerHTML="<input type=text size=25 maxlength=50 name=diagnosis ln="+allCount+" class=tableData onkeyup='modifiedIt()'>"
c4=newRow.insertCell(3);
c4.ln=allCount;
c4.innerHTML="<input type=text size=58 maxlength=100 name=medication ln="+allCount+" class=tableData onkeyup='modifiedIt()'>"
allCount++
}
function mouseOver()
{
event.srcElement.className="delMouseOver"
}
function mouseOut()
{
event.srcElement.className="scheduleButtonVisible"
}
</SCRIPT>

sallina 2002-10-18
  • 打赏
  • 举报
回复
主要功能:

1.动态增加行

2.可以点击表格左边的按钮删除当前行,如果该行有数据会要求用户确认删除

3.表格可以实现动态编辑

4.通过点击某一行可以实现高亮度显示

源代码:

===================================

<HTML>
<HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE type=text/css>BODY {
BACKGROUND: white; COLOR: black; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableData {
BACKGROUND: white; BORDER-BOTTOM: white 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: white 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataSel {
BACKGROUND: #6090d0; BORDER-BOTTOM: #6090d0 1px dashed; BORDER-LEFT: #6090d0 1px dashed; BORDER-RIGHT: #6090d0 1px dashed; BORDER-TOP: #6090d0 1px dashed; COLOR: white; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataHit {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.tableDataOver {
BACKGROUND: #d0e0ff; BORDER-BOTTOM: #d0e0ff 1px dashed; BORDER-LEFT: #d0e0ff 1px dashed; BORDER-RIGHT: #d0e0ff 1px dashed; BORDER-TOP: #d0e0ff 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 12px
}
.controlPanel {
BACKGROUND: silver; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.controlPanelMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.delMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; FONT-FAMILY: verdana,arial,helvetica; FONT-SIZE: 14px
}
.scheduleButtonVisible {
BACKGROUND: silver; BORDER-BOTTOM: gray 1px dashed; BORDER-LEFT: white 1px dashed; BORDER-RIGHT: gray 1px dashed; BORDER-TOP: white 1px dashed; COLOR: black; CURSOR: hand; FONT-FAMILY: webdings; FONT-SIZE: 12px
}
</STYLE>

internetibm 2002-10-18
  • 打赏
  • 举报
回复
to 十一:
我想把<input type=text>放在表格之中可以删除一行;
ssm1226 2002-10-18
  • 打赏
  • 举报
回复
<table id=t border=1 width=100%>
<tr>
<td>品名</td>
<td>单价</td>
<td>产地</td>
</tr>
<form name=frm>
<tr>
<td><input id=product name=product></td>
<td><input name=price id=price></td>
<td><input type=text name=city tabindex="0" onkeypress="if(event.keyCode==13) test()"></td>
</tr>
</form>
</table>
<SCRIPT LANGUAGE=javascript>
<!--
var arr=new Array();
arr[0]="<input id=product name=product>";
arr[1]="<input name=price id=price>";
arr[2]="<input type=text name=city tabindex='0' onkeypress='if(event.keyCode==13) test()'>";

function test(){
var intTablelen=t.rows.length;
var objevent=event.srcElement;
var intIdx=objevent.tabIndex;
var objProduct=frm.product;
var objPrice=frm.price;
var strProduct="",strPrice="";

if(objProduct.length!=undefined){
strProduct=objProduct[intIdx].value;
strPrice=objPrice[intIdx].value;
}else{
strProduct=objProduct.value;
strPrice=objPrice.value;
}
if(strProduct!='' && strPrice!=''){
var aa=t.insertRow();
for(var i=0;i<3;i++){
aa.insertCell().innerHTML=arr[i]}}

frm.city.tabIndex=(parseInt(intTablelen)-1).toString();
alert(frm.city.tabIndex)
}
//-->
</SCRIPT>
方工 2002-10-18
  • 打赏
  • 举报
回复
在表格的最后按回车增加行比较麻烦,看看这个行否:
<html>
<head>
<title> 动态表格</title>
<script language="JavaScript">
function addNew(){
if( event.keyCode==13 && brand.value!="" && price.value!="" && fac.value!=""){
var r=tab1.insertRow();
r.insertCell().innerText = brand.value;
r.insertCell().innerText = price.value;
r.insertCell().innerText = fac.value;
}
}
</script>
</head>
<body>

品名<input id=brand size=10>单价<input id=price size=8>产地<input id=fac onkeydown="addNew()">
<table id=tab1 border=1>
<tr>
<td width=100>品名</td>
<td width=100>单价</td>
<td width=100>产地</td>
</tr>
</table>
</body>
</html>
gq 2002-10-18
  • 打赏
  • 举报
回复
<table>
<tr>
<td>品名| 单价| 产地 | </td>
</tr>
<% do while not rs.eof%>
<tr><td><%rs(0)%>之类</td></tr>
<%rs.movenext
loop%>
<tr> <td> </td></tr>
</table>


87,940

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧