高分求解(关于父子窗口交互和动态表格)

Times2001 2006-09-11 03:05:45
parent.html:父窗口文件,
sub.html:子窗口文件。
父窗口如下,点“选择”后弹出子窗口。
------------------------------------------------------------
| [选择] |
| ------------------------------------------------------ |
| | 书名 | 出版社 | 作者 | 删除 | |
| +----------------------------------------------------+ |
| | | |


子窗口如下,在多选了子窗口内的书后,点下面的“选择”,则在父窗口中增加选择的多条书的信息。


------------------------------------------------------------
| 查询条件1: 查询条件2: |
| |
| +----------------------------------------------------+ |
| | 书名 | 出版社 | 作者 | 选择 | |
| +-------+--------------------+-----------------------+ |
| | book1 |******* |***** | 多选框 | |
| | book2 |******* |***** | 多选框 | |
| | book3 |******* |***** | 多选框 | |
| | book4 |******* |***** | 多选框 | |
| +-------+--------------------+-------------+---------+ |
| |
| [选择] |


请高手提供解决办法,最好是有实例代码?
解决后,我会另开两个百分贴感谢!
...全文
420 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
fisyxiaojing 2007-01-22
  • 打赏
  • 举报
回复
up
BlueDestiny 2006-09-11
  • 打赏
  • 举报
回复
noname2.html
-----------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> - http://www.never-online.net </title>
<meta http-equiv="ImageToolbar" content="no" />
<meta name="author" content="never-online, BlueDestiny"/>
<script type="text/javascript">
//<![CDATA[
var prefixName = "neverOnline";
var openerElementId = 'tbl';
var checkBoxName = "cb";

function FnGetRow(o) {
while (o.tagName!="TR") {
o = o.parentNode;
}; return o;
}
function FnBar(o) {
var oTr = FnGetRow(o);
var $ = window.opener.document.getElementById;
var oTbl = $(openerElementId);
try { var e = $(prefixName+o.value); } catch(ex) {};
if (o.checked) {
if (e) return; else {
var tr = oTbl.insertRow();
tr.id = prefixName+o.value;
for (var i=0; i<oTr.cells.length; i++) {
var td = tr.insertCell(i);
td.innerHTML = oTr.cells[i].innerHTML;
}
}
} else {
e?e.parentNode.removeChild(e):"";
}
}

//]]>
</script>
</head>
<body id="www.never-online.net">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><input type="checkbox" name="cb" value="1"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="2"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="3"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="4"/></td>
<td>information</td>
</tr>
</table>
<script type="text/javascript">
//<![CDATA[
var FnLoadEvent = function() {
var a = document.getElementsByName(checkBoxName);
for (var i=0; i<a.length; i++) {
a[i].onclick = function() { FnBar(this); }
}
}();
//]]>
</script>
</body>
</html>
BlueDestiny 2006-09-11
  • 打赏
  • 举报
回复
noname1.html
---------------------
<body id="www.never-online.net">
<script type="text/javascript">
//<![CDATA[
function FnOpenWindow(sPageUrl) {
var w = window.open(sPageUrl);
}
//]]>
</script>
<button onclick="FnOpenWindow('noname2.html')">compare</button>
<table border="1" cellpadding="0" cellspacing="0" width="100%" id="tbl">
</table>
</body>
fosjos 2006-09-11
  • 打赏
  • 举报
回复
感觉还是用tr显示和隐藏比较方便
happilygirl 2006-09-11
  • 打赏
  • 举报
回复
2、opener.document.父窗体from.父窗体控件.value=document.form2.子窗体控件.value;
将子窗体中的值传给父窗体。
happilygirl 2006-09-11
  • 打赏
  • 举报
回复
1、window.open('子文件名.html','名')可以打开子窗体
Times2001 2006-09-11
  • 打赏
  • 举报
回复
本贴暂时不结,希望大家完善或提供更好的实现方式。有好的实现可以另开贴给分!
Times2001 2006-09-11
  • 打赏
  • 举报
回复
to xuStanly(黑金):
感谢!请到下面两贴接分!(你赚我这两百分可并不难哦~ :-) )
http://community.csdn.net/Expert/TopicView3.asp?id=5014061
http://community.csdn.net/Expert/TopicView3.asp?id=5014064
BlueDestiny 2006-09-11
  • 打赏
  • 举报
回复
那也不难的,也就是字符串操作...
Times2001 2006-09-11
  • 打赏
  • 举报
回复
to BlueDestiny(blog.never-online.net):
非常感谢你提供代码,不过你的代码和我希望的有些出入,你的实现方式是通过服务器交互的。我希望完全在客户端通过javascript实现。
xuStanly 2006-09-11
  • 打赏
  • 举报
回复
parent.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>

<body>
<input type="button" value="选择" onclick="window.open('sub.html','','width=400,height=300,status=1')">
<table id="tp" border="1"></table>
</body>
</html>


sub.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script>
function sel(){
var obj = document.getElementsByTagName("input");
var id; //行号
var pid;//父窗口新增行的行号
var cell;//父窗口新增的单元格
for(i=0;i<obj.length;i++){
if(obj[i].checked){
id = obj[i].parentNode.parentNode.rowIndex;
pid = opener.tp.insertRow();
for(n=0;n<3;n++){
cell = pid.insertCell();
cell.innerText = ts.rows[id].cells[n].innerText;
}
}
}
}
</script>
</head>

<body>
<table id="ts" border="1">
<tr><td>123</td><td>123</td><td>123</td><td><input type="checkbox"></td></tr>
<tr><td>456</td><td>456</td><td>456</td><td><input type="checkbox"></td></tr>
<tr><td>789</td><td>789</td><td>789</td><td><input type="checkbox"></td></tr>
<tr><td colspan="4"><input type="button" value="选择" onclick="sel()"></td></tr>
</table>
</body>
</html>
Times2001 2006-09-11
  • 打赏
  • 举报
回复
to xuStanly(黑金):
你的建议和我的想法差不多,这样确实很麻烦,我再想有没有读写一整行的方法。
BlueDestiny 2006-09-11
  • 打赏
  • 举报
回复
子窗口用Request获取传递过来的集合到数据库里查询即可
BlueDestiny 2006-09-11
  • 打赏
  • 举报
回复
<body id="www.never-online.net">
<script type="text/javascript">
//<![CDATA[
function FnCompare(sPageUrl) {
var a = document.getElementsByName("cb");
var v = ''; for (var i=0; i<a.length; i++) {
a[i].checked?v += a[i].value+(i==a.length-1?'':','):'';
}
sPageUrl = sPageUrl+'?q='+v;
window.alert(sPageUrl);
window.open(sPageUrl,'','');
}
//]]>
</script>
<button onclick="FnCompare('compare.aspx')">compare</button>
<table border="1" cellpadding="0" cellspacing="0" width="100%" >
<tr>
<td><input type="checkbox" name="cb" value="1"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="2"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="3"/></td>
<td>information</td>
</tr>
<tr>
<td><input type="checkbox" name="cb" value="4"/></td>
<td>information</td>
</tr>
</table>
</body>
Times2001 2006-09-11
  • 打赏
  • 举报
回复
to andrewy():
注册的时候加上去的,修改注册资料也可以修改,但现在我没找到在哪里修改资料。

andrewy 2006-09-11
  • 打赏
  • 举报
回复
楼上的大哥你咋不回答我的问题呢?括号里的字咋加上去的?
xuStanly 2006-09-11
  • 打赏
  • 举报
回复
楼主这100分就不好赚呐。
具体的大段代码贴起来不方便,楼主看起来只怕也会晕。给个思路吧。
在sub.htm中,取得哪个些多选框被选中,然后再得到被选中的多选框在table的哪一行,得到行号,根据行号把相应的单元格中的innerText取出,在parent.htm中在相应的table中inertRow()插入一行,然后把事先取出的innerText填进去。
andrewy 2006-09-11
  • 打赏
  • 举报
回复
帮顶,顺便问一个问题.楼主的用户名:Times2001 (回车) 括号里的注释是怎么加上去的?

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧