请教一个关于javascript父窗口打开子窗口的问题,为什么子窗口里的window.opener是undefined
demo2.jsp的代码<formname="form1"action="test.html"method="post">客户id:<inputtype="text"na...
demo2.jsp的代码
<form name="form1" action="test.html" method="post" >
客户id: <input type="text" name="cid" value="" id="cid" ><br>
客户名称<input type="text" name="cname" value="" id="cname" >
<input type="button" name="ok" value="请选择客户" onclick="openWin();"/>
</form>
<script type="text/javascript">
function openWin(){
window.open("index.jsp",null, "_blank", "toolbar=no,status=no");
}
</script>
<script type="text/javascript">
function viewData(pid,name){
//得到父窗口的对象
alert(window.opener);
var parentwindow= window.opener;
parentwindow.document.getElementById("cid").value=pid;
parentwindow.document.getElementById("cname").value=name;
window.close();
}
</script>
<body>
<table border="1">
<body>
<form name="form1" action="test.html" method="post" >
客户id: <input type="text" name="cid" value="" id="cid" ><br>
客户名称<input type="text" name="cname" value="" id="cname" >
<input type="button" name="ok" value="请选择客户" onclick="openWin();"/>
</form>
<script type="text/javascript">
function openWin(){
window.open("index.jsp", "_blank", "toolbar=no,status=no");
}
</script>
</body>
index.jsp
<tr>
<td>操作</td>
<td>客户id</td>
<td>客户名称</td>
</tr>
<tr>
<td><input type="button" value="选择" id="ss" onclick="viewData('001','深圳华为');"></td>
<td>001</td>
<td>深圳华为</td>
</tr>
<tr>
<td><input type="button" value="选择" onclick="viewData('002','用友软件');"> </td>
<td>002</td>
<td>用友软件</td>
</tr>
</table>
</body>
中间重复粘贴了。。 展开
<form name="form1" action="test.html" method="post" >
客户id: <input type="text" name="cid" value="" id="cid" ><br>
客户名称<input type="text" name="cname" value="" id="cname" >
<input type="button" name="ok" value="请选择客户" onclick="openWin();"/>
</form>
<script type="text/javascript">
function openWin(){
window.open("index.jsp",null, "_blank", "toolbar=no,status=no");
}
</script>
<script type="text/javascript">
function viewData(pid,name){
//得到父窗口的对象
alert(window.opener);
var parentwindow= window.opener;
parentwindow.document.getElementById("cid").value=pid;
parentwindow.document.getElementById("cname").value=name;
window.close();
}
</script>
<body>
<table border="1">
<body>
<form name="form1" action="test.html" method="post" >
客户id: <input type="text" name="cid" value="" id="cid" ><br>
客户名称<input type="text" name="cname" value="" id="cname" >
<input type="button" name="ok" value="请选择客户" onclick="openWin();"/>
</form>
<script type="text/javascript">
function openWin(){
window.open("index.jsp", "_blank", "toolbar=no,status=no");
}
</script>
</body>
index.jsp
<tr>
<td>操作</td>
<td>客户id</td>
<td>客户名称</td>
</tr>
<tr>
<td><input type="button" value="选择" id="ss" onclick="viewData('001','深圳华为');"></td>
<td>001</td>
<td>深圳华为</td>
</tr>
<tr>
<td><input type="button" value="选择" onclick="viewData('002','用友软件');"> </td>
<td>002</td>
<td>用友软件</td>
</tr>
</table>
</body>
中间重复粘贴了。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询