newRow id = "tdt"; //行88,调试器提示缺少';'
newRow ln = allCount;
===>
newRow.id = "tdt"; //行88,调试器提示缺少';'
newRow.ln = allCount;
newRow ln = allCount;
===>
newRow.id = "tdt"; //行88,调试器提示缺少';'
newRow.ln = allCount;
这一行应该没敲错啊。
c1.innerHTML = "<input type=text name='popgroup' ln='+allCount+' class=tableData />";
c1.innerHTML = "<input type=text name='popgroup' ln="+allCount+" class=tableData />";
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<STYLE type=text/css>
BODY {
BACKGROUND: white; COLOR: black; font:menu
}
.tableData {
BACKGROUND: white; BORDER-BOTTOM: red 1px dashed; BORDER-LEFT: green 1px dashed; BORDER-RIGHT: blue 1px dashed; BORDER-TOP: #FFCC00 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:menu
}
.controlPanelMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; font:menu
}
.delMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; font:menu
}
.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
//highlight a line
function lightOn(ln)
{
if (ln==null)
ln=parseInt(event.srcElement.ln,10)
for (i=1;i<PopGroup.rows.length;i++)
if (tdt[i].ln==ln)
line=i
cln=currentLine
oldLine=-1
for (i=1;i<PopGroup.rows.length;i++)
if (tdt[i].ln==cln)
oldLine=i
if (line==oldLine)
return
//if td <0 then only clear all titleif (line>0)
{
document.all.tdt[line].className="tableDataHit";
document.popform("pop")[line].className="tableDataHit";if (oldLine>0)
{
document.all.tdt[oldLine].className="tableData";
document.popform("pop")[oldLine].className="tableData";
}
currentLine=ln
}
}
function addNewline() //add a line to the table
{
var PopGroup = document.getElementById('PopGroup');
newRow = PopGroup.insertRow(PopGroup.rows.length);newRow.setAttribute('id', "tdt"); //行88,调试器提示缺少';'
newRow.setAttribute('ln',allCount);
newRow.bgColor="#e0e0e0";
newRow.onclik = lightOn;
c1=newRow.insertCell(0);
c1.ln=allCount;
c1.innerHTML = "<input type=text name=\"popgroup\" ln="+allCount+" />";c2 = newRow.insertCell(1);
c2.ln=allCount;
c2.innerHTML="<input type=text name=\"pop\" ln="+allCount+" class=tableData />";c3 = newRow.insertCell(2);
c3.ln=allCount;
c3.innerHTML="<input type=text name=\"pop\" ln="+allCount+" class=tableData />";c4 = newRow.insertCell(3);
c4.ln=allCount;
c4.innerHTML="<input type=text name=\"pop\" ln="+allCount+" class=tableData />";c5 = newRow.insertCell(4);
c5.ln=allCount;
c5.innerHTML="<input type=text name=\"pop\" ln="+allCount+" class=tableData />";
allCount++;
}
</SCRIPT></head><body bgcolor="white">
<form id="form1" name="popform" method="post" action="">
<DIV id=div1 style="LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 658px">
<table align="center" width="775" height="158" border="1" id="PopGroup" rules="rows">
<tr id="tdt">
<th width="144" scope="col"> </th>
<th width="144" scope="col">white</th>
<th width="144" scope="col">black</th>
<th width="144" scope="col">Hispanic</th>
<th width="165" scope="col">others</th>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="1">
<td>
<input name="popgroup" type="text" id="popgroup" value="<20 year old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="2">
<td>
<input name="popgroup" type="text" id="popgroup" value="20-24 year old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="3">
<td>
<input name="popgroup" type="text" id="popgroup" value=">24 years old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
</table>
<script>
allCount=4
</script><table align="center"> <!-- this table is for the control pannel, ex, add, delete, etc -->
<tbody>
<tr>
<td >
<input type="button" value="add a line" onclick="addNewline()"/> //行191,提示缺少对象
<input type="button" value="delete a line" />
<input type="button" value="move up" />
<input type="button" value="move down" />
</td>
</tr>
</tbody>
</table>
</DIV>
</form>
</body>
</html>
ln="+allCount" 为什么要两个 “+”号。
这样不行吗: ln="allCount"
而且为什么这里用双引号,而name='popgroup'用单引号?
谢谢 myvicy的回答。
应该是+popgroup+
不过你放心,这个改完了还有错
我本来想改到能运行,但我伤心了,改不出来
完全看不懂你的企图.
不知道你现在懂些了我的企图没有。
在myvicy的帮助下我实现了添加行的功能,下面是我完整的代码:
-----------start--------------<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Untitled Document</title>
<STYLE type=text/css>
BODY {
BACKGROUND: white; COLOR: black; font:menu
}
.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:menu
}
.controlPanelMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; font:menu
}
.delMouseOver {
BACKGROUND: #d0e0ff; COLOR: black; CURSOR: hand; font:menu
}
.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
//select a line
function lightOn(ln)
{
if (ln==null)
ln=parseInt(event.srcElement.ln,10)
for (i=1;i<PopGroup.rows.length;i++)
if (tdt[i].ln==ln)
line=i
cln=currentLine
oldLine=-1
for (i=1;i<PopGroup.rows.length;i++)
if (tdt[i].ln==cln)
oldLine=i
if (line==oldLine)
return
//if td <0 then only clear all titleif (line>0)
{
document.all.tdt[line].className="tableDataHit";
document.popform("pop")[line].className="tableDataHit";if (oldLine>0)
{
document.all.tdt[oldLine].className="tableData";
document.popform("pop")[oldLine].className="tableData";
}
currentLine=ln
}
}/*
function move(direc) //move the selected line
{
if(line+direc<1||(line+direc)>document.all.tdt.length-1) return;
var temp = document.popform.pop[line].value;
document.popform.pop[line].value=document.popform.pop[lien+direc].value;
document.popform.pop[line+direc].value = temp;
line+=direc;
lightOn(line);
} */
function addNewline()
{
newRow = PopGroup.insertRow(PopGroup.rows.length);
newRow.id = "tdt";
newRow.ln = allCount;
//newRow.bgColor="#e0e0e0";
newRow.onclik = lightOn;c1=newRow.insertCell(0);
c1.ln=allCount;
c1.innerHTML = "<input type=text name='popgroup' ln="+allCount+" class=tableData />";c2 = newRow.insertCell(1);
c2.ln=allCount;
c2.innerHTML="<input type=text name='pop' ln="+allCount+" class=tableData />";c3 = newRow.insertCell(2);
c3.ln=allCount;
c3.innerHTML="<input type=text name='pop' ln="+allCount+" class=tableData />";c4 = newRow.insertCell(3);
c4.ln=allCount;
c4.innerHTML="<input type=text name='pop' ln="+allCount+" class=tableData />";c5 = newRow.insertCell(4);
c5.ln=allCount;
c5.innerHTML="<input type=text name='pop' ln="+allCount+" class=tableData />";
allCount++;
}
</SCRIPT></head><body bgcolor="white">
<form id="form1" name="popform" method="post" action="">
<DIV id=div1 style="LEFT: 0px; POSITION: absolute; TOP: 0px; VISIBILITY: visible; WIDTH: 658px">
<table align="center" width="775" height="158" border="1" id="PopGroup" rules="all">
<tr id="tdt">
<th width="144" scope="col"> </th>
<th width="144" scope="col">white</th>
<th width="144" scope="col">black</th>
<th width="144" scope="col">Hispanic</th>
<th width="165" scope="col">others</th>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="1">
<td>
<input name="popgroup" type="text" id="popgroup" value="<20 year old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="2">
<td>
<input name="popgroup" type="text" id="popgroup" value="20-24 year old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
<tr id="tdt" class="tableData" onclick="lightOn()" ln="3">
<td>
<input name="popgroup" type="text" id="popgroup" value=">24 years old" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
<td>
<input name="pop" type="text" class="tableData" id="pop" />
</td>
</tr>
</table>
<script>
allCount=4
</script>
<table align="center"> <!-- this table is for the control pannel, ex, add, delete, etc -->
<tbody>
<tr>
<td >
<input type="button" value="add a line" onclick="addNewline()"/>
<input type="button" value="delete a line" />
<input type="button" value="move up" />
<input type="button" value="move down" />
</td>
</tr>
</tbody>
</table>
</DIV>
</form>
</body>
</html>
--------------end--------------------------------------
不过里面选中一行的功能没有实现,也没有报错。不知道怎么回事
应该是+popgroup+为什么要用"+popgroup+"了,这里用两个加号是什么意思。谢谢。