<HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
iIndex = 0;
function showIndex(){
alert(iIndex);
}
function getIndex(){
iIndex = event.srcElement.parentElement.rowIndex;
}
function insertRow(iPos){
var otr=myTable.insertRow(iPos);
var ocell=otr.insertCell(0);
ocell.innerHTML=" "
var ocell=otr.insertCell(1);
ocell.innerHTML=" "
}
function deleteRow(iPos){
document.all.myTable.deleteRow(iPos);
}
</SCRIPT>
</HEAD>
<BODY>
<table id="myTable" border=1>
<tr onclick="getIndex()">
<td>1</td>
<td>2</td>
</tr>
<tr onclick="getIndex()">
<td>1</td>
<td>2</td>
</tr>
</table>
<form>
<input type=button onclick="alert(iIndex)" value="show Index">
<input type=button onclick="insertRow(iIndex)" value="插入行">
<input type=button onclick="deleteRow(iIndex)" value="删除行">
<input type=button onclick="location.reload();" value="返回">
</form>
</BODY>
</HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">
iIndex = 0;
function showIndex(){
alert(iIndex);
}
function getIndex(){
iIndex = event.srcElement.parentElement.rowIndex;
}
function insertRow(iPos){
var otr=myTable.insertRow(iPos);
var ocell=otr.insertCell(0);
ocell.innerHTML=" "
var ocell=otr.insertCell(1);
ocell.innerHTML=" "
}
function deleteRow(iPos){
document.all.myTable.deleteRow(iPos);
}
</SCRIPT>
</HEAD>
<BODY>
<table id="myTable" border=1>
<tr onclick="getIndex()">
<td>1</td>
<td>2</td>
</tr>
<tr onclick="getIndex()">
<td>1</td>
<td>2</td>
</tr>
</table>
<form>
<input type=button onclick="alert(iIndex)" value="show Index">
<input type=button onclick="insertRow(iIndex)" value="插入行">
<input type=button onclick="deleteRow(iIndex)" value="删除行">
<input type=button onclick="location.reload();" value="返回">
</form>
</BODY>
</HTML>
在某个页面比如table3中,动态增加了几个行,然后链接到其它页面,由于某种原因需要回到table3,这时发现,动态增加的行没有了.怎样让动态增加的行,在这种情况下还在?
楼上发的东西,我明天在研究,
请各位大虾执教。
把改动传到数据库
把改动写到文件
你发过来的示例能解决静态对象的保值效果,但不能保留动态增加的对象。
估计这个问题,只能用动态网页技术了。
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JK:支持民族工业,尽量少买X货</title><style>
TD,INPUT{ font-size:12; }
</style>
</head><body bgcolor=EEEEEE>
<form name="frm" action="about:结果页面" method=post >
<h4 align=center>JK的动态明细示例</h4><table align="center" bordercolor=cccccc border=1 width=100% >
<tr>
<td width=500>
</td>
<td align=right>
<input type="button" value="增加" class="bottom" onclick="addDetailProcess();">
<input type="button" value="删除" class="bottom" onclick="delDetailProcess();">
<input type="button" value="完成" class="bottom" onclick="submitProcess();">
</td>
</tr>
</table>
<div width=100% id=thedetailtableDIV>
<table align="center" bordercolor=cccccc border=1 width=100% >
<tbody id="tbDetailPrepare">
<tr>
<td ><input type="checkbox" name="record_select" ></td>
<td ><input type="text" name="detail_id" value='' ></td>
<td ><input type="text" name="detail_name" value='' ></td>
</tr>
</tbody>
<tr bgcolor=eeeeee id="trDetailTitles">
<td ><input type=checkbox onclick="selectallcheckbox(this)"></td>
<td >明细ID*</td>
<td >明细NAME</td>
</tr>
<tbody id="tbDetailUsed" >
<tr>
<td ><input type="checkbox" name="record_select" ></td>
<td ><input type="text" name="detail_id" value='' ></td>
<td ><input type="text" name="detail_name" value='' ></td>
</tr> <tr height=0 ><td colspan=100 height=0 > 合计</td></tr>
</tbody> </table>
</div>
</form><input name="theHistoryRecord" type=hidden value="">
</body></html><script language=javascript> window.onload = historyOncemore;
window.onbeforeunload = fixHistory; function fixHistory() //记住历史
{
document.all("theHistoryRecord").value=document.all("thedetailtableDIV").innerHTML.replace(/\n/g,"");
} function historyOncemore() //恢复历史
{
if (document.all("theHistoryRecord").value!="")
{document.all("thedetailtableDIV").innerHTML=document.all("theHistoryRecord").value;
}
} function selectallcheckbox(obj) //全选或全不选
{
var tureorfalse=obj.checked;
var theDetail=tbDetailUsed.rows;
for(var i=0;i<theDetail.length-1;i++)
{
theDetail[i].all("record_select").checked=tureorfalse;
}
}
function addDetailProcess(afterRowIndex) //增加明细
{
var alltbDetailUsed= document.all("tbDetailUsed").rows;
var theFirstSelectedDetail;
if (afterRowIndex==null)
{
for(var i=0;i<alltbDetailUsed.length-1;i++)
{
if (alltbDetailUsed[i].all("record_select").checked==true) {theFirstSelectedDetail=i;break;}
}
if (theFirstSelectedDetail==null) {theFirstSelectedDetail=alltbDetailUsed.length-2;}
}
else theFirstSelectedDetail=afterRowIndex;
var newRow = document.all("tbDetailPrepare").rows[0].cloneNode(true);
var desRow = alltbDetailUsed[theFirstSelectedDetail+1];
desRow.parentElement.insertBefore(newRow,desRow ); }
function delDetailProcess() //删除明细
{
var alltbDetailUsed= document.all("tbDetailUsed").rows;
if (confirm("确定选择正确并且要将这些明细删除")==false) return false;
for(var i=0;i<alltbDetailUsed.length-1;i++)
{
if (alltbDetailUsed[i].all("record_select").checked==true)
{
document.all("tbDetailUsed").deleteRow(i);
i=i-1;
}
}
} function submitProcess()
{
document.frm.submit();
}
</script>
这里有一事不明,网页在unload后,怎么那个对象的值还能保存呢?这里的机制是怎样的?
是不是有个缓冲(存)机制?或者整个网页对象并没有被destroy掉,那么unlaod到底做了什么呢?
我已经另外开了帖子表示对JK_10000(JK) 的感谢,本贴主要用来对其他参与大虾的感谢。
请指点。
之后从计算机内存中取出以下的值赋上:
text-input________value
hidden-input______value
radio-input_______checked
checkbox-input____checked
select____________selectedIndex
option____________selected
textarea__________value(innerText)
之后再执行onload的事件页面unload时情况恰相反
先将以上值放在内存中(同记录页面history一起)
再进行unload
http://community.csdn.net/Expert/topic/3532/3532874.xml?temp=.2830469
眼前的问题是:那个隐藏的对象怎么unload后,还能保存值呢?
另外,我如果把window.load换成body.load就不行了,这是怎么回事?
可以在html的参考资料上看到关于body对象的一段注释:
The window object for the BODY element can host event handlers for the onblur, onfocus, onload, or onunload events.
但是onbeforeunload似乎就不能在body里帮window定义了(没试过,但应该是这样的)。