怎么在父窗口的函数里面,获取子窗口的值? function getall(formname) { ssss.value = document.frames["subpage"].document.getElementsByName("ttt").value; } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function getall(formname) { ssss.value = document.frames["subpage"].document.getElementsByName("ttt").value; }??框架??不是,是模拟窗口阿! <input name=ttt>这里还是最好用ID吧..getElementsByName取得的是组.对框架的引用window.frames[下标或者框架名字] 父窗口函数<input id =ssss> function getall(formname) { ssss.value = win.cc() //改为调用子子窗口的函数来获得ttt的值(win为用window.open函数打开的窗口的name) }子窗口<input id=ttt>onclick = "opener.getall()" //改为opener调用父窗口函数funciton cc(){ return ttt.value;} <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!--function setValue(obj){try{ document.Form1.txt1.value= obj.document.getElementById("btn1").value ;}catch(e){ alert(e.description);}}function openWin(){ objWin = showModalDialog('CallOpenerFunction-2-ttt.htm', window,'dialogWidth: 480px; dialogHeight: 360px; status: no; help: no');}function fndownload(url){ window.open(url);}//--></SCRIPT></HEAD><BODY><FORM name="Form1" METHOD=POST ACTION=""><INPUT TYPE="text" NAME="txt1" value="default"><INPUT TYPE="button" NAME="abc" onclick="openWin()" value="openWin"></FORM></BODY></HTML>--------------'CallOpenerFunction-2-ttt.htm'----------------<input id="btn1" type='button' value='SetValue' onclick='if (window.dialogArguments != null)window.dialogArguments.setValue(this);window.opener=null;window.close();'> To CutBug() 在子窗口中,就是因为无法直接执行JS的函数,我才迫不得已这么做的。 obj就是子窗口对象,你愿意怎么遍历就怎么遍历。 代码移植过去之后说是window.dialogArguments 对象为空,不正确的,你可以下载我给的那个页面,测试看看。遍历函数就在里面,可能要修改一下,谢谢了。搞定了再散。 我现在访问不了其他网站。如果为空,你看看showModalDialog调用的时候,有没有把父窗体的 window对象 当作参数传过去。 ssss.value = window.frames[0].document.forms[0].ttt.value; <script language="javascript">var alternateFrame=null;//生成的iframevar alternateWin=null;window.alert=showAlert;window.confirm=showConfirm;/** * 人机交互窗口,覆盖自带的 */function alternateWindow(){this.win=null;//生成对话框的窗口对象this.pBody=null;//生成的body容器对象this.pBg=null;this.type="open";//默认的种类是alertthis.FocusWhere="OK";//焦点在哪个按钮上}/** * 模仿的alert窗口 */function showAlert(info){alternateWin=new alternateWindow();var pBody = alternateWin.init();alternateWin.initAlertBody(pBody,info);alternateWin.type="alert";} /** * 模仿的alert窗口 */function showConfirm(info,ok_func,notok_func,ok_str,not_okstr){alternateWin=new alternateWindow();var pBody = alternateWin.init();alternateWin.initConfirmBody(pBody,info,ok_func,notok_func,ok_str,not_okstr);alternateWin.type="confirm";}/** * 作用:初始基本信息 */alternateWindow.prototype.init=function() {if(alternateFrame==null){alternateFrame=document.createElement("<iframe allowTransparency='true' id='popframe' frameborder=0 marginheight=0 src='about:blank' marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>")alternateFrame.style.position="absolute";document.body.appendChild(alternateFrame);}else{alternateFrame.style.visibility="visible";}alternateFrame.style.width=screen.availWidth;alternateFrame.style.height=screen.availHeight;alternateFrame.style.left=document.body.scrollLeft;alternateFrame.style.top=document.body.scrollTop;alternateFrame.name=alternateFrame.uniqueID;this.win=window.frames[alternateFrame.name];this.win.document.write("<body leftmargin=0 topmargin=0 oncontextmenu='self.event.returnValue=false'><div id=popbg></div><div id=popbody></div><div></div></body>");this.win.document.body.style.backgroundColor="transparent";document.body.style.overflow="hidden";this.pBody=this.win.document.body.children[1];this.pBg=this.win.document.body.children[0];this.hideAllSelect();this.initBg();return this.pBody;} /*** 作用:初始化背景层 */alternateWindow.prototype.initBg=function(){with(this.pBg.style){position="absolute";left="0";top="0";width="100%";height="100%";visibility="hidden";backgroundColor="#333333";filter="blendTrans(duration=1) alpha(opacity=30)";}this.pBg.filters.blendTrans.apply();this.pBg.style.visibility="visible";this.pBg.filters.blendTrans.play();}/** * 作用:初始化显示层 */alternateWindow.prototype.initAlertBody=function(obj,info){with(obj.style){position="absolute";width="400";height="150";backgroundColor="#ffffff";}obj.style.left=window.document.body.clientWidth/2-200;obj.style.top=window.document.body.clientHeight/3;var str;//dialogArguments.vDialog=null;str ="<table border=0 cellpadding=0 cellspacing=1 bgcolor=#000000 width=100% height=100%><form id='form1' name='form1'><tr height=30>";str+="<td align=left style='color:#000000;font-size:14px;font-weight:bold' bgcolor=#9999ff>[提示]</td></tr>";str+="<tr><td align=center bgcolor=#efefff style='font-size:12px;color:#000000;vertical-align: middle;'>";str+=info+"<input type=text id=ttt><input type=text id=rrr><input type=text id=uuu><input type='button' onclick='parent.getall();' value='传递文字'></td></tr><tr height=30 bgcolor=#efefef><td align=center>" + "<input type='button' value='确定' id='OK'" + " onkeydown='parent.alternateWin.onKeyDown(event,this)'"+ " onclick='parent.alternateWin.closeWin()' style='border:solid 1px #666666;background:#cccccc'>" + "</td></tr></form></table>";obj.innerHTML=str;this.win.document.body.all.OK.focus();this.FocusWhere="OK";}alternateWindow.prototype.onKeyDown=function(event,obj){ switch(event.keyCode){ case 9: event.keyCode=-1; if(this.type=="confirm"){ if(this.FocusWhere=="OK"){ this.win.document.body.all.NO.focus(); this.FocusWhere="NO"; }else{ this.win.document.body.all.OK.focus(); this.FocusWhere="OK"; } } break; case 13:obj.click();;break; case 27:this.closeWin();break; } }/** * 作用:关闭一切 */alternateWindow.prototype.closeWin=function(){alternateFrame.style.visibility="hidden"; this.showAllSelect();document.body.style.overflow="auto"; }/** * 作用:隐藏所有的select */alternateWindow.prototype.hideAllSelect=function(){ var obj; obj=document.getElementsByTagName("SELECT"); var i; for(i=0;i<obj.length;i++)obj[i].style.visibility="hidden"; }/** * 显示所有的select */ alternateWindow.prototype.showAllSelect=function(){ var obj; obj=document.getElementsByTagName("SELECT"); var i; for(i=0;i<obj.length;i++)obj[i].style.visibility="visible";}function formToRequestString(formname){ var query_string=''; var form_obj = document.getElementById(formname).elements; for (var i=0;i<form_obj.length ;i++) { var e=form_obj[i]; if (e.name!='') { var element_value = ""; if (e.type.toLowerCase()=='select'){ element_value=e.options[e.selectedIndex].value; }else if (e.type.toLowerCase()=='checkbox' || e.type.toLowerCase()=='radio'){ if (e.checked==false){ continue; } element_value=e.value; }else{ element_value=e.value; } query_string+=e.name+'='+element_value.replace(/\&/g,"%26") + '&'; } } return query_string;}</script><script> function getall() { ssss.value = document.getElementsById("ttt").value; } </script><input name=ssss type=text><div id=naeee></div><body><button onclick="alert('');">跳出新窗口传值</button></body>把代码发上来。。看看吧 <script> function getall() { document.getElementById("ssss").value = window.frames[0].document.getElementById("ttt").value; } </script> 用javsscript 如果获取页面中的 title 和 keywords 简单问题 保存效果 为什么这段代码不好使 请教textarea的当前浏览行 jqtreetable 数据多加载慢怎么解决 关于在线编辑器的问题,请做过的近来帮帮忙!!!!!(高分,分不够再加) 请教高手:iframe有没有location对象?本人在js里设置location.reload(true)时,client老实报object is null or is not object 有缺陷的菜单,请帮我解决 怎么判断文本框中输入的有中文字符? 请问如何改变一个控件在网页中的位置 如何替换??谢谢
ssss.value = document.frames["subpage"].document.getElementsByName("ttt").value;
}
??框架??
不是,是模拟窗口阿!
对框架的引用window.frames[下标或者框架名字]
父窗口函数
<input id =ssss>
function getall(formname)
{
ssss.value = win.cc() //改为调用子子窗口的函数来获得ttt的值(win为用window.open函数打开的窗口的name)
}子窗口
<input id=ttt>
onclick = "opener.getall()" //改为opener调用父窗口函数
funciton cc()
{
return ttt.value;
}
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function setValue(obj){
try{
document.Form1.txt1.value= obj.document.getElementById("btn1").value ;
}catch(e){
alert(e.description);
}
}function openWin(){
objWin = showModalDialog('CallOpenerFunction-2-ttt.htm', window,'dialogWidth: 480px; dialogHeight: 360px; status: no; help: no');
}
function fndownload(url){
window.open(url);
}
//-->
</SCRIPT>
</HEAD><BODY>
<FORM name="Form1" METHOD=POST ACTION="">
<INPUT TYPE="text" NAME="txt1" value="default">
<INPUT TYPE="button" NAME="abc" onclick="openWin()" value="openWin">
</FORM>
</BODY>
</HTML>--------------'CallOpenerFunction-2-ttt.htm'----------------
<input id="btn1" type='button' value='SetValue' onclick='if (window.dialogArguments != null)window.dialogArguments.setValue(this);window.opener=null;window.close();'>
搞定了再散。
如果为空,你看看
showModalDialog调用的时候,有没有把父窗体的 window对象 当作参数传过去。
var alternateWin=null;window.alert=showAlert;
window.confirm=showConfirm;/**
* 人机交互窗口,覆盖自带的
*/
function alternateWindow(){
this.win=null;//生成对话框的窗口对象
this.pBody=null;//生成的body容器对象
this.pBg=null;
this.type="open";//默认的种类是alert
this.FocusWhere="OK";//焦点在哪个按钮上
}
/**
* 模仿的alert窗口
*/
function showAlert(info){
alternateWin=new alternateWindow();
var pBody = alternateWin.init();
alternateWin.initAlertBody(pBody,info);
alternateWin.type="alert";
}
/**
* 模仿的alert窗口
*/
function showConfirm(info,ok_func,notok_func,ok_str,not_okstr){
alternateWin=new alternateWindow();
var pBody = alternateWin.init();
alternateWin.initConfirmBody(pBody,info,ok_func,notok_func,ok_str,not_okstr);
alternateWin.type="confirm";
}
/**
* 作用:初始基本信息
*/
alternateWindow.prototype.init=function() {
if(alternateFrame==null){
alternateFrame=document.createElement("<iframe allowTransparency='true' id='popframe' frameborder=0 marginheight=0 src='about:blank' marginwidth=0 hspace=0 vspace=0 scrolling=no></iframe>")
alternateFrame.style.position="absolute";
document.body.appendChild(alternateFrame);
}else{
alternateFrame.style.visibility="visible";
}
alternateFrame.style.width=screen.availWidth;
alternateFrame.style.height=screen.availHeight;
alternateFrame.style.left=document.body.scrollLeft;
alternateFrame.style.top=document.body.scrollTop;
alternateFrame.name=alternateFrame.uniqueID;this.win=window.frames[alternateFrame.name];
this.win.document.write("<body leftmargin=0 topmargin=0 oncontextmenu='self.event.returnValue=false'><div id=popbg></div><div id=popbody></div><div></div></body>");
this.win.document.body.style.backgroundColor="transparent";
document.body.style.overflow="hidden";
this.pBody=this.win.document.body.children[1];
this.pBg=this.win.document.body.children[0];
this.hideAllSelect();
this.initBg();return this.pBody;
} /**
* 作用:初始化背景层
*/
alternateWindow.prototype.initBg=function(){
with(this.pBg.style){
position="absolute";
left="0";
top="0";
width="100%";
height="100%";
visibility="hidden";
backgroundColor="#333333";
filter="blendTrans(duration=1) alpha(opacity=30)";
}
this.pBg.filters.blendTrans.apply();
this.pBg.style.visibility="visible";
this.pBg.filters.blendTrans.play();
}
/**
* 作用:初始化显示层
*/
alternateWindow.prototype.initAlertBody=function(obj,info){
with(obj.style){
position="absolute";
width="400";
height="150";
backgroundColor="#ffffff";
}
obj.style.left=window.document.body.clientWidth/2-200;
obj.style.top=window.document.body.clientHeight/3;
var str;
//dialogArguments.vDialog=null;
str ="<table border=0 cellpadding=0 cellspacing=1 bgcolor=#000000 width=100% height=100%><form id='form1' name='form1'><tr height=30>";
str+="<td align=left style='color:#000000;font-size:14px;font-weight:bold' bgcolor=#9999ff>[提示]</td></tr>";
str+="<tr><td align=center bgcolor=#efefff style='font-size:12px;color:#000000;vertical-align: middle;'>";
str+=info+"<input type=text id=ttt><input type=text id=rrr><input type=text id=uuu><input type='button' onclick='parent.getall();' value='传递文字'></td></tr><tr height=30 bgcolor=#efefef><td align=center>" +
"<input type='button' value='确定' id='OK'" +
" onkeydown='parent.alternateWin.onKeyDown(event,this)'"+
" onclick='parent.alternateWin.closeWin()' style='border:solid 1px #666666;background:#cccccc'>" +
"</td></tr></form></table>";
obj.innerHTML=str;
this.win.document.body.all.OK.focus();
this.FocusWhere="OK";
}alternateWindow.prototype.onKeyDown=function(event,obj){
switch(event.keyCode){
case 9:
event.keyCode=-1;
if(this.type=="confirm"){
if(this.FocusWhere=="OK"){
this.win.document.body.all.NO.focus();
this.FocusWhere="NO";
}else{
this.win.document.body.all.OK.focus();
this.FocusWhere="OK";
}
}
break;
case 13:obj.click();;break;
case 27:this.closeWin();break;
} }/**
* 作用:关闭一切
*/
alternateWindow.prototype.closeWin=function(){
alternateFrame.style.visibility="hidden";
this.showAllSelect();
document.body.style.overflow="auto";
}
/**
* 作用:隐藏所有的select
*/
alternateWindow.prototype.hideAllSelect=function(){
var obj;
obj=document.getElementsByTagName("SELECT");
var i;
for(i=0;i<obj.length;i++)
obj[i].style.visibility="hidden";
}
/**
* 显示所有的select
*/
alternateWindow.prototype.showAllSelect=function(){
var obj;
obj=document.getElementsByTagName("SELECT");
var i;
for(i=0;i<obj.length;i++)
obj[i].style.visibility="visible";
}function formToRequestString(formname)
{
var query_string=''; var form_obj = document.getElementById(formname).elements;
for (var i=0;i<form_obj.length ;i++)
{
var e=form_obj[i];
if (e.name!='')
{
var element_value = "";
if (e.type.toLowerCase()=='select'){
element_value=e.options[e.selectedIndex].value;
}else if (e.type.toLowerCase()=='checkbox' || e.type.toLowerCase()=='radio'){
if (e.checked==false){
continue;
}
element_value=e.value;
}else{
element_value=e.value;
}
query_string+=e.name+'='+element_value.replace(/\&/g,"%26") + '&';
} }
return query_string;
}
</script><script>
function getall() {
ssss.value = document.getElementsById("ttt").value;
}
</script>
<input name=ssss type=text>
<div id=naeee></div>
<body>
<button onclick="alert('');">跳出新窗口传值</button>
</body>把代码发上来。。看看吧
function getall() {
document.getElementById("ssss").value = window.frames[0].document.getElementById("ttt").value;
}
</script>