忘了以下代码,实现主窗口中表行动态增加
<input type="button" class="form1" value="增加商品" onClick="addLine()">
<input type="button" class="form1" value="增加商品" onClick="addLine()">
解决方案 »
- jquery 如何查询div 的 id 类似于 name_div_name_1
- Jquery如何选择现在mouseover的div的子元素
- 怎么利用javascript外部文件制作表格?
- JS框架页调用父页JS函数.
- 有何方法使页面刷新的时候不执行onunload事件
- 刷新问题:A窗口弹出一个B窗口,我想在A窗口中刷新B窗口,怎么做啊?谢谢!
- var win="window.open('*.htm','','width=100,height=100');"的问题。
- 很急!按纽操作文本框
- js问题
- html action中的地址写在js中
- JK_10000版主请进
- 在自定义的函数传递了一个变量,但在用时出现未定义错误。。。。急~~~
{
if(obj.rowIndex!=0)
{
//这里,因为你clone了一行,这行里面的pcode就变两个了所以得用索引来访问了.
//=====pcode[1].value=============
//window.opener.document.jhform.pcode.value=obj.childNodes[0].innerText;
window.opener.document.jhform.pcode[1].value=obj.childNodes[0].innerText; /////B处 ==
window.close();
}
}
来访问
为你的隐藏了的行中的name="pcode"的控件
<thead id="thead1">
<TR style="display:none" bgColor="#ffffff">
<td width="15%" height="22" align="center">
<input readonly name="pcode" type="text" size="10" class="wenbenkuang"> //////A处
<input name="Submit3" type="button" class="form1" value="选择" onClick="javascript:window.open( '/myjxc/listProductOnly ', ' ', 'width=550,height=330,left=0,top=0 ')"> </td>
<td width="27%" align="center"> </td>
<td width="10%" align="center"> </td>
<td width="9%" align="center"> </td>
<td width="6%" align="center"> </td>
<td width="8%" align="center"> <input type="text" name="dj" size="8" class="wenbenkuang"> </td>
<td width="8%" align="center"> <input type="text" name="sl" size="8" class="wenbenkuang"> </td>
<td width="13%" align="center"> <input readonly type="text" name="je" size="10" class="wenbenkuang"> </td>
<td align="center"> <img src="../images/delete.gif" width="20" height="20"> </td>
</TR>
</thead>
麻烦再指导,谢谢!!
var nowLine=0;//默认为你隐藏的那行
function addLine(){
elm=thead1.lastChild.cloneNode(true)
elm.style.display="";
tbody1.insertBefore(elm);
nowLine++;//添加了一行
} 弹出窗口的js
function show(obj)
{
if(obj.rowIndex!=0)
{ //使用opener的nowLine变量来访问name="pcode"的子控件
window.opener.document.jhform.pcode[opener.nowLine].value=obj.childNodes[0].innerText; /////B处 ==
window.close();
}
}
1.htm
<html>
<head></head>
<body>
<form name="jhform" action="" method="post">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#86c2fe">
<thead id="thead1">
<TR style="display:none" bgColor="#ffffff">
<td width="15%" height="22" align="center">
<input readonly name="pcode" type="text" size="10" class="wenbenkuang"> //////A处
<input name="Submit3" type="button" class="form1" value="选择" onClick="javascript:window.open('2.htm ', '', 'width=550,height=330,left=0,top=0')"> </td>
<td width="27%" align="center"> </td>
<td width="10%" align="center"> </td>
<td width="9%" align="center"> </td>
<td width="6%" align="center"> </td>
<td width="8%" align="center"> <input type="text" name="dj" size="8" class="wenbenkuang"> </td>
<td width="8%" align="center"> <input type="text" name="sl" size="8" class="wenbenkuang"> </td>
<td width="13%" align="center"> <input readonly type="text" name="je" size="10" class="wenbenkuang"> </td>
<td align="center"> <img src="../images/delete.gif" width="20" height="20"> </td>
</TR>
</thead>
<tbody id="tbody1">
<tr bgcolor="#C4DDF6">
<td width="15%" height="22" align="center"> 商品代码 </td>
<td width="27%" align="center" class="big"> 商品名称 </td>
<td width="10%" align="center" class="big_b"> 类别 </td>
<td width="9%" align="center" class="big"> 规格 </td>
<td width="6%" align="center" class="big"> 单位 </td>
<td width="8%" align="center" class="big"> 单价 </td>
<td width="8%" align="center" class="big"> 数量 </td>
<td width="13%" align="center" class="big"> 金额 </td>
<td width="4%" align="center" class="big"> 操作 </td>
</tr>
</tbody>
</table>
</form>
<input type="button" class="form1" value="增加商品" onClick="addLine()">
<SCRIPT LANGUAGE="JavaScript">
var nowLine=0;//默认为你隐藏的那行
function addLine(){
elm=thead1.lastChild.cloneNode(true)
elm.style.display="";
tbody1.insertBefore(elm);
nowLine++;//添加了一行
}
</script>
</body>
</html>2.htm
<html>
<head></head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#86c2fe">
<tr bgcolor="#C4DDF6">
<td width="9%" height="20" align="center"> 商品代码 </td>
<td width="16%" align="center" class="big"> 商品名称 </td>
<td width="12%" align="center" class="big_b"> 商品类别 </td>
<td width="8%" align="center" class="big"> 规格 </td>
<td width="9%" align="center" class="big"> 单位 </td>
<td width="16%" align="center" class="big"> 产地 </td>
<td align="center" class="big"> 生产厂商 </td>
</tr>
<tr style="cursor:hand" onmouseover="this.bgColor= '#f0f0f0 '" onMouseOut="this.bgColor= '#ffffff '" bgColor="#ffffff">
<td width="9%" height="26" align="center"> aaa </td>
<td width="16%" align="center"> bbb </td>
<td width="12%" align="center"> ccc </td>
<td width="8%" align="center"> ddd </td>
<td width="9%" align="center"> eee </td>
<td width="16%" align="center"> fff </td>
<td width="20%" align="center"> ggg </td>
</tr>
</c:forEach>
</table>
<style>
tr{t:expression(this.ondblclick=function(){show(this)})}
</style>
<script language=javascript>
function show(obj)
{
if(obj.rowIndex!=0)
{
window.opener.document.jhform.pcode[opener.nowLine].value=obj.childNodes[0].innerText; /////B处 ==
window.close();
}
}
</script> </body>
</html>
<html>
<head></head>
<body>
<form name="jhform" action="" method="post">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#86c2fe">
<thead id="thead1">
<TR style="display:none" bgColor="#ffffff">
<td width="15%" height="22" align="center">
<input readonly name="pcode" type="text" size="10" class="wenbenkuang">
<input name="Submit3" type="button" class="form1" value="选择" >
<input type="button" onclick="tbody1.removeChild(this.parentNode.parentNode);" value="删除"/></td>
<td width="27%" align="center"> </td>
<td width="10%" align="center"> </td>
<td width="9%" align="center"> </td>
<td width="6%" align="center"> </td>
<td width="8%" align="center"> <input type="text" name="dj" size="8" class="wenbenkuang"> </td>
<td width="8%" align="center"> <input type="text" name="sl" size="8" class="wenbenkuang"> </td>
<td width="13%" align="center"> <input readonly type="text" name="je" size="10" class="wenbenkuang"> </td>
<td align="center"> <img src="../images/delete.gif" width="20" height="20"> </td>
</TR>
</thead>
<tbody id="tbody1">
<tr bgcolor="#C4DDF6">
<td width="15%" height="22" align="center"> 商品代码 </td>
<td width="27%" align="center" class="big"> 商品名称 </td>
<td width="10%" align="center" class="big_b"> 类别 </td>
<td width="9%" align="center" class="big"> 规格 </td>
<td width="6%" align="center" class="big"> 单位 </td>
<td width="8%" align="center" class="big"> 单价 </td>
<td width="8%" align="center" class="big"> 数量 </td>
<td width="13%" align="center" class="big"> 金额 </td>
<td width="4%" align="center" class="big"> 操作 </td>
</tr>
</tbody>
</table>
</form>
<input type="button" class="form1" value="增加商品" onClick="addLine()">
<SCRIPT LANGUAGE="JavaScript">
var Index=0;//生成唯一id的变量,从0开始
function addLine(){
elm=thead1.lastChild.cloneNode(true)
var es=elm.getElementsByTagName("input");
var ID="";
for(var i=0;i<es.length;i++)
{
if(es[i].name=="pcode")
{
ID="pcode"+Index;//生成唯一id
es[i].id=ID;
}
else if(es[i].name=="Submit3")
{
es[i].onclick=function()//把打开窗口选择数据的单击事件放到这里
{
window.open('2.htm?'+ID, '', 'width=550,height=330,left=0,top=0');//把这个pcode的id加上
}
}
}
elm.style.display="";
tbody1.insertBefore(elm);
Index++;//id加1以便生存唯一id
}
</script>
</body>
</html>
2.htm
<html>
<head></head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#86c2fe">
<tr bgcolor="#C4DDF6">
<td width="9%" height="20" align="center"> 商品代码 </td>
<td width="16%" align="center" class="big"> 商品名称 </td>
<td width="12%" align="center" class="big_b"> 商品类别 </td>
<td width="8%" align="center" class="big"> 规格 </td>
<td width="9%" align="center" class="big"> 单位 </td>
<td width="16%" align="center" class="big"> 产地 </td>
<td align="center" class="big"> 生产厂商 </td>
</tr>
<tr style="cursor:hand" onmouseover="this.bgColor= '#f0f0f0 '" onMouseOut="this.bgColor= '#ffffff '" bgColor="#ffffff">
<td width="9%" height="26" align="center"> aaa </td>
<td width="16%" align="center"> bbb </td>
<td width="12%" align="center"> ccc </td>
<td width="8%" align="center"> ddd </td>
<td width="9%" align="center"> eee </td>
<td width="16%" align="center"> fff </td>
<td width="20%" align="center"> ggg </td>
</tr>
</c:forEach>
</table>
<style>
tr{t:expression(this.ondblclick=function(){show(this)})}
</style>
<script language="javascript">function show(obj)
{
var NowLineId=location.search.substring(1);//从查询字符串获取要操作的opener上的控件id
if(obj.rowIndex!=0)
{
opener.document.getElementById(NowLineId).value=obj.childNodes[0].innerText;
window.close();
}
}
</script>
</body>
</html>