在网页中怎样实现向下填充的功能。高分求救
我想问下,在网页中有一个表格10行,其中有输入框,现在,我想实现当焦点在一个输入框,去点击一个"向下填充"按钮,从而把此输入框下面的值取与此框相同的值。同列的输入框只是ID的最后一个字符不同,所以比较容易循环。现在是我怎么在点击
"向下填充"按钮时,得到刚才焦点所在输入框的值以及ID阿。用document.activeElement不行啊,因为在点击按钮时,按钮就成为活动元素那。
真的很急啊,跪求各位能给予代码实现。谢谢
问题点数:80、回复次数:2Top
1 楼LxcJie(肖冲*爱*捷捷)回复于 2004-08-03 10:25:16 得分 0
在输入框的onfocus事件中记录此输入框
<input type="text" onfocus="window.inputObj = this'">
这样,点击按钮时就可以从全局变量window.inputObj中去到了,记得使用完把window.inputObj = null;
Top
2 楼LxcJie(肖冲*爱*捷捷)回复于 2004-08-03 12:02:08 得分 80
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<STYLE>
input{width:70px; border:1px solid black;}
</STYLE>
<BODY>
<TABLE width="70%" id="fillTable" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">
<TR>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
</TR>
<TR>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
</TR>
<TR>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
</TR>
<TR>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
</TR>
<TR>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
<TD><INPUT onFocus="window.inputObj = this"/></TD>
</TR>
</TABLE><p>
<INPUT type="button" value="向下填充" onClick="fill()" >
<script language="javascript">
function fill()
{
if(!window.inputObj)
return;
var oTable = document.all.fillTable;
var oTdIndex = window.inputObj.parentNode.cellIndex;
for(var i=0; i<oTable.rows.length; i++)
{
for(var j=0; j<oTable.rows[i].cells.length; j++)
{
if(j == oTdIndex)
oTable.rows[i].cells[j].children[0].value = window.inputObj.value;
}
}
}
</script>
</BODY>Top




