首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

百分询问一个关于window.opener.document.getElementById的有关问题

2012-10-20 
百分询问一个关于window.opener.document.getElementById的问题在网上搜了好多,都没有很好的解决办法,说什

百分询问一个关于window.opener.document.getElementById的问题
在网上搜了好多,都没有很好的解决办法,说什么的都有,在这里想在弄懂这个方法的使用。
我在父页面中调用了子页面,用的是window.open方式,
具体代码如下:

JScript code
    function emuladd(){        newopen = window.open("","test","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=200,left=100,width=850,height=450");        document.forms[0].action="testAddLowCusAllInfo.html?selectButtonMenu=5&flag="+'booking';        document.forms[0].target="test";        document.forms[0].submit();        intervalFunc = setInterval('reloadPage()',10);    }    function reloadPage(){        if(newopen.closed){            window.clearInterval(intervalFunc);            window.location.href = "bizBookingProStartOpen.html?projectkind="+$('projectkind').value;        }    }


然后在进入的子页面中加入了以下代码:
JScript code
         alert("保存成功");    window.opener.document.getElementById("index_0011").value = $('customname').value;         window.close();


以上的customname是我在子窗口中得到的值,index_0011是位于父页面的文本框,现在我要做的就是对子页面进行保存后,自动关闭子页面,并将其中子页面中的一个特定的文本框的值传入父页面中,可是这种方法不可行,在父页面中是得不到值的,请高手帮忙,是不是需要修改哪些地方,还是需要检查什么其他元素,非常感谢?

[解决办法]
LZ 的思路正确,这里有一简单的方法,合乎你的要求,有什么问题就提出
父窗口. (名字随意)
HTML code
<html xmlns="http://www.w3.org/1999/xhtml" ><head>    <title>无标题页</title><script language="javascript">function openwin(){    var url="2.html";    var mydata=showModalDialog(url,null,"dialogWidth:300px;dialogHeight:120px;center:yes;help:No;status:no;resizable:Yes;edge:sunken");//得到子窗口返回值    if(mydata)     alert("您从子窗口输入的值为:" +mydata.value);}</script></head><body>    <input id="Button1" type="button" value="打开窗口" onclick="openwin()" /></body></html>
[解决办法]
window.opener --> parent
[解决办法]
HTML code
<script>function $(s){  return document.getElementById(s);}function emuladd(){        newopen = window.open("","test","status=no,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=200,left=100,width=850,height=450");        document.forms[0].action="testAddLowCusAllInfo.html?selectButtonMenu=5&flag="+'booking';        document.forms[0].target="test";        document.forms[0].submit();        intervalFunc = setInterval('reloadPage()',10);    }    function reloadPage(){        if(newopen.closed){            window.clearInterval(intervalFunc);            window.location.href = "bizBookingProStartOpen.html?projectkind="+$('projectkind').value;        }    }</script><form><input type="text" id="index_0011"><input type="text" id="projectkind" value="xxx"><input type="button" onclick="emuladd()"></form>
[解决办法]
没有任何问题。
把 $('customname').value; 改成字符串 常量 试试。
[解决办法]
用法是没有任何问题的。父窗口得不到值应该是其他方面的原因。代码列举的不详细,不能判断具体原因。
可先alert下$('customname').value的值,看看能否得到。

热点排行