求助,如何把表单里的值存储到一个vector里?javascript我不熟悉.

ylfly 2004-11-01 12:46:55
最好每增加一行的时候,值就保存起来,然后一起提交

page.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href="EditTable.css" type=text/css rel=stylesheet>
<script language="javascript" src="EditTable.js"></script>
</head>
<body>

<select id=typecode size=6 style="position:absolute;display:none" onblur="this.style.display='none'" onchange="setInputFromSelect(inputFocus,this)">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>

<form name=form action="">
<TABLE width="750" border=0 cellPadding=0 cellSpacing=1 bgColor=#000000 cols=1 id=table7B1 rules=rows >
<thead>
<tr bgColor=#ffffff>
<th class=thData width=1%><input type=checkbox id=checkLineAll onclick=setOnlineEditCheckBox(getUpperObj(this,"TABLE"),this.checked)></th>
<th class=thData width=22%>ITEM_NUMBER</th>
<th class=thData width=33%>TYPECODE</th>
<th class=thData width=22%>QUANTITY</th>
<th class=thData width=22%>TICKET_NUMBER</th>
</tr>
<TR style="display:none" class=tableData onclick=lightonRow(this)>
<TD class=scheduleButtonVisible ><input type=checkbox id=checkLine></td><!--Fixed-->
<TD><input class=inputTableData name=x></TD>
<TD><input class=inputTableData readonly="true" name=y onclick=showInputSelect(this,typecode) onblur=hideInput(typecode)></TD>
<TD><input class=inputTableData name=z></TD>
<TD><input class=inputTableData name=m></TD>
</TR>
</thead>
<tbody>
</tbody>
</TABLE>
</form>
<center>
<input type=button class="input1" onClick = "history.go(-1);" value="返回">
<input type=button class="input1" onclick="addRow(table7B1)" value="添加">
<input type=button class="input1" onclick="deleteRow(table7B1)" value="删除">
<input type=button class="input1" onclick="clearRow(table7B1)" value="删除全部">
<input type=button class="input1" onclick="form.submit()" value="确定">
<input type=button class="input1" onclick="form.reset()" value="重置">
</center>
</p>
</body>
</html>
---------------------------------------------------------------------------------------
EditTable.js文件

//全局变量
var inputFocus;//该变量记录当前焦点的input

function setRowClass(obj,className){
obj.className=className;
var oldClass,toClass;
if(className=="tableData") {oldClass="inputTableDataHit";toClass="inputTableData";}
if(className=="tableDataHit") {oldClass="inputTableData";toClass="inputTableDataHit";}
var objsInput=obj.all;
for(var i=0;i<objsInput.length;i++)
if(objsInput[i].tagName=="INPUT")if(objsInput[i].className==oldClass)objsInput[i].className=toClass;
}

function lightonRow(obj){
if(obj.tagName!="TR")return;

//将所有未被选中的行取消高亮度现实
var tableOnlineEdit=obj.parentElement;
while(tableOnlineEdit.tagName!="TABLE")tableOnlineEdit=tableOnlineEdit.parentElement;
var objsCheckBox=tableOnlineEdit.all("checkLine");
for(var iCheckBox=1;iCheckBox<objsCheckBox.length;iCheckBox++)
if(objsCheckBox[iCheckBox].checked==false) setRowClass(tableOnlineEdit.rows[iCheckBox+1],"tableData");

//当前点击行高亮度显示
setRowClass(obj,"tableDataHit");
}

//得到obj的上级元素TagName
function getUpperObj(obj,TagName){
var strTagName=TagName.toUpperCase();
var objUpper=obj.parentElement;
while(objUpper){
if(objUpper.tagName==strTagName) break;
objUpper=objUpper.parentElement;
}
return objUpper;
}

function getPosition(obj,pos){
var t=eval("obj."+pos);
while(obj=obj.offsetParent){
t+=eval("obj."+pos);
}
return t;
}

function showInputSelect(obj,objShow){
inputFocus=obj;//记录当前焦点input至全局变量
objShow.style.top =getPosition(obj,"offsetTop")+obj.offsetHeight+2;
objShow.style.left=getPosition(obj,"offsetLeft");
objShow.style.width=obj.offsetWidth;
objShow.value=obj.value;
objShow.style.display="block";
}

function setInputFromSelect(objTo,objShow){
objTo.value=objShow.options[objShow.selectedIndex].value;
}

function hideInput(obj){
obj.style.display="none";
}

function clearRow(objTable){
var tbodyOnlineEdit=objTable.getElementsByTagName("TBODY")[0];
for (var i=tbodyOnlineEdit.children.length-1;i>=0;i--)
tbodyOnlineEdit.deleteRow(i);
}

function deleteRow(objTable){
var tbodyOnlineEdit=objTable.getElementsByTagName("TBODY")[0];
for (var i=tbodyOnlineEdit.children.length-1; i>=0 ; i-- )
if (tbodyOnlineEdit.children[i].firstChild.firstChild.checked)
tbodyOnlineEdit.deleteRow(i);
}

function addRow(objTable){
var tbodyOnlineEdit=objTable.getElementsByTagName("TBODY")[0];
var theadOnlineEdit=objTable.getElementsByTagName("THEAD")[0];
var elm = theadOnlineEdit.lastChild.cloneNode(true);
elm.style.display="";
tbodyOnlineEdit.insertBefore(elm);
}

//将指定数据行的objRow的输入域strName设置为strValue
function setInputValue(objRow,strName,strValue){
var objs=objRow.all;
for(var i=0;i<objs.length;i++){
if(objs[i].name==strName)objs[i].value=strValue;
}
}

//将全部复选框设为指定值
function setOnlineEditCheckBox(obj,value){
var tbodyOnlineEdit=obj.getElementsByTagName("TBODY")[0];
for (var i=tbodyOnlineEdit.children.length-1; i>=0 ; i-- )
tbodyOnlineEdit.children[i].firstChild.firstChild.checked=value;
}

//得到光标的位置
function getCursorPosition(obj){
var qswh="@#%#^&#*$"
obj.focus();
rng=document.selection.createRange();
rng.text=qswh;
var nPosition=obj.value.indexOf(qswh)
rng.moveStart("character", -qswh.length)
rng.text="";
return nPosition;
}

//设置光标位置
function setCursorPosition(obj,position){
range=obj.createTextRange();
range.collapse(true);
range.moveStart('character',position);
range.select();
}
-----------------------------------------------------------------------------------------
EditTable.css文件

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
}
.inputTableDataHit {
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;width:100%
}
.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
}
.scheduleButtonVisible {
BACKGROUND: silver; BORDER-BOTTOM: white 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
}
...全文
161 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
blues-star 2004-11-02
  • 打赏
  • 举报
回复
request.getParameter
ylfly 2004-11-01
  • 打赏
  • 举报
回复
如何在JSP或者servlet里用vector接收动动态数据,现在只接受到一行
ylfly 2004-11-01
  • 打赏
  • 举报
回复
谢谢,我试试
ylfly 2004-11-01
  • 打赏
  • 举报
回复
高手们..在JSP里怎么才能接收到动态表单提交的数据啊.用vector接收.在线等待
ttyp 2004-11-01
  • 打赏
  • 举报
回复
function Vector()
{
this.data = new Array();
this.add = Vector_add;
this.remove = Vector_remove;
this.elementAt = Vector_elementAt;
this.setElementAt = Vector_setElementAt;
this.insert = Vector_insert;
this.contains = Vector_contains;
this.length = Vector_length;
this.toString = Vector_toString;
}

function Vector_add( item )
{
this.data[ this.data.length ] = item;
}

function Vector_remove( index )
{
var data = this.data;
data[ index ] = null;
var tmpdata = new Array();
var newindex = 0;
for( var i = 0; i < data.length; i++ )
{
if( data[ i ] != null )
{
tmpdata[ newindex ] = data[ i ];
newindex++;
}
}
this.data = tmpdata;
}

function Vector_removeItem( item )
{
var data = this.data;
var tmpdata = new Array();
var newindex = 0;
for( var i = 0; i < data.length; i++ )
{
if( data[ i ] != item )
{
tmpdata[ newindex ] = data[ i ];
}
newindex++;
}
this.data = tmpdata;
}

function Vector_elementAt( index )
{
return this.data[ index ];
}

function Vector_setElementAt( index, item )
{
this.data[ index ] = item;
}

function Vector_insert( index, item )
{
if( index == this.data.length )
{
this.add( item );
return;
}
var data = this.data;
var tmpdata = new Array();
var newindex = 0;
for( var i = 0; i < data.length; i++ )
{
if( i == index )
{
tmpdata[ i ] = item;
newindex++;
}
tmpdata[ newindex ] = data[ i ];
newindex++;
}
this.data = tmpdata;
}

function Vector_contains( item )
{
for( var i = 0; i < this.data.length; i++ )
{
if( this.data[i] == item )
{
return true;
}
}
return false;
}

function Vector_length()
{
return this.data.length;
}

function Vector_toString()
{
var dataString = "[ ";
var data = this.data;
for( var i = 0; i < data.length; i++ )
{
dataString += data[i] + " ";
}
dataString += "]";
return dataString;
}

//http://community.csdn.net/Expert/topic/3448/3448802.xml?temp=.4298059
ylfly 2004-11-01
  • 打赏
  • 举报
回复
等待高手....
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-11-01 12:46
社区公告
暂无公告