window.open出来的页面中可以设置父页面select中option的值么? window.parent.form1.deptsel.options[toLength]=new Option("Hello","lllll"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 window.opener.document.form1.deptsel.options[toLength]=new Option('hello','11111') //-- 变通一下test1.html<script language=javascript> function btnTest_onclick(){ form1.deptsel.options[0]=new Option('hello1','bds1'); form1.deptsel.options[1]=new Option('hello2','bds2'); form1.deptsel.options[2]=new Option('hello3','bds3'); } function btnTest2_onclick(){ window.open("test2.html"); } function funcTest(){ alert("I love this game !"); }</script><form name=form1><table border=1 align=center> <tr> <td> <select name=deptsel> <option value="value1">value1</option> <option value="value2">value2</option> <option value="value3">value3</option> </select> </td> </tr></table><input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();"><input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();"><input type="button" name=btnTest3 value="测 试3" onclick="funcTest();"></form>//******************************************************************test2.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><button onclick=test()>test</button><SCRIPT LANGUAGE="JavaScript"><!--function test(){ window.opener.btnTest_onclick();}//--></SCRIPT></body></html> test2.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><button onclick=test()>test</button><SCRIPT LANGUAGE="JavaScript"><!--function test(){ window.opener.btnTest_onclick();}//--></SCRIPT></body></html>//**************************************************************test3.html<script language=javascript> function btnTest_onclick(){ form1.deptsel.options[0]=new Option('hello1','bds1'); form1.deptsel.options[1]=new Option('hello2','bds2'); form1.deptsel.options[2]=new Option('hello3','bds3'); } function btnTest2_onclick(){ window.open("test2.html"); } function funcTest(){ alert("I love this game !"); }</script><form name=form1><table border=1 align=center> <tr> <td> <select name=deptsel> <option value="value1">value1</option> <option value="value2">value2</option> <option value="value3">value3</option> </select> </td> </tr></table><input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();"><input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();"><input type="button" name=btnTest3 value="测 试3" onclick="funcTest();"></form> opener.document.all.form1.deptsel.options[toLength]=new Option('hello','11111');就没问题,form1是你表单的name,deptsel是你select的name 很感谢铁鹰,但是我需要的是在子页面中得到的值(比如是一个select中所选option的值)去赋值给父页面,而不是跳回调父页面中的function 因为权限问题,只能用length++再赋值的方法,看例子<script>function mynew(){mynew=window.open('sub.htm','newwindow','');}function add(){form1.kk.add(new Option("text","value"),1);//add/*tmp="s123";form1.kk.options[0] = new Option(tmp,tmp);//change*/}</script><body onload=mynew()><form name=form1><input type=button value=change&add onclick="add()"><select name=kk><option value=1>1<option value=12>12<option value=13>13</select></form>sub.htm<form name=myform><select name=myselect><option value=s1>s1<option value=s12>s12<option value=s13>s13</select><input type="button" name="but1" value="change&addopener" onclick=passBack()></form><script>function passBack() { if(document.myform.myselect.options.length!=0){ tmp=document.myform.myselect.options[document.myform.myselect.selectedIndex].text; }//add//opener.document.form1.kk.add(new Option("text","value"),1);//服务器错opener.document.forms[0].kk.length++;opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].text =tmp;opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].value =tmp;/*//changeopener.document.forms[0].kk.options[0] = new Option(tmp,tmp);//服务器错opener.document.forms[0].kk.options[0].text =tmp;opener.document.forms[0].kk.options[0].value =tmp;*/}</script> test2.html<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><button onclick=test()>test</button><SCRIPT LANGUAGE="JavaScript">function test(){ var options=window.opener.form1.deptsel.options; window.opener.btnTest_onclick(options[0].value+"mytest",options[1].value+"mytest",2);}</SCRIPT></body></html>//**************************************************************<script language=javascript> function btnTest_onclick(var1,var2,position1){ form1.deptsel.options[position1]=new Option(var1,var2); } function btnTest2_onclick(){ window.open("test2.html"); }</script><form name=form1><table border=1 align=center> <tr> <td> <select name=deptsel> <option value="value1">value1</option> <option value="value2">value2</option> <option value="value3">value3</option> </select> </td> </tr></table><!--<input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">--><input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();"></form> 在Chrome下如何加载xml文件 怎样一个DIV的宽度? 怎么在JS中和<object>控件对象交互 超炫效果!超高难度ajax排序问题 JS日期选择器问题 求FLASH与SQL数据库连接,并提取想要的内容. Javascript失效 一个在关闭窗口时弹出一个新窗口的问题 请教高手,如何在页面里弹出一个保存文件对话框? 急,急,急,请大哥们帮帮忙吧! ****当选择IE菜单--〉文字大小来改变页面字体大小的时候,能否在点击完该菜单选项后响应一个JS程序(如弹出警告alert窗口)? 这段程序怎么修改啊~
test1.html<script language=javascript>
function btnTest_onclick(){
form1.deptsel.options[0]=new Option('hello1','bds1');
form1.deptsel.options[1]=new Option('hello2','bds2');
form1.deptsel.options[2]=new Option('hello3','bds3');
} function btnTest2_onclick(){
window.open("test2.html");
} function funcTest(){
alert("I love this game !");
}
</script>
<form name=form1>
<table border=1 align=center>
<tr>
<td>
<select name=deptsel>
<option value="value1">value1</option>
<option value="value2">value2</option>
<option value="value3">value3</option>
</select>
</td>
</tr>
</table>
<input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">
<input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
<input type="button" name=btnTest3 value="测 试3" onclick="funcTest();">
</form>
//******************************************************************
test2.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body><button onclick=test()>test</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test()
{
window.opener.btnTest_onclick();
}
//-->
</SCRIPT>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body><button onclick=test()>test</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function test()
{
window.opener.btnTest_onclick();
}
//-->
</SCRIPT>
</body>
</html>
//**************************************************************
test3.html
<script language=javascript>
function btnTest_onclick(){
form1.deptsel.options[0]=new Option('hello1','bds1');
form1.deptsel.options[1]=new Option('hello2','bds2');
form1.deptsel.options[2]=new Option('hello3','bds3');
} function btnTest2_onclick(){
window.open("test2.html");
} function funcTest(){
alert("I love this game !");
}
</script>
<form name=form1>
<table border=1 align=center>
<tr>
<td>
<select name=deptsel>
<option value="value1">value1</option>
<option value="value2">value2</option>
<option value="value3">value3</option>
</select>
</td>
</tr>
</table>
<input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">
<input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
<input type="button" name=btnTest3 value="测 试3" onclick="funcTest();">
</form>
就没问题,form1是你表单的name,deptsel是你select的name
<script>
function mynew()
{
mynew=window.open('sub.htm','newwindow','');
}
function add()
{
form1.kk.add(new Option("text","value"),1);
//add
/*tmp="s123";
form1.kk.options[0] = new Option(tmp,tmp);
//change
*/
}
</script>
<body onload=mynew()>
<form name=form1>
<input type=button value=change&add onclick="add()">
<select name=kk>
<option value=1>1
<option value=12>12
<option value=13>13
</select>
</form>sub.htm
<form name=myform>
<select name=myselect>
<option value=s1>s1
<option value=s12>s12
<option value=s13>s13
</select>
<input type="button" name="but1" value="change&addopener" onclick=passBack()>
</form>
<script>
function passBack() {
if(document.myform.myselect.options.length!=0){
tmp=document.myform.myselect.options[document.myform.myselect.selectedIndex].text;
}//add
//opener.document.form1.kk.add(new Option("text","value"),1);//服务器错
opener.document.forms[0].kk.length++;
opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].text =tmp;
opener.document.forms[0].kk.options[opener.document.forms[0].kk.length-1].value =tmp;/*
//change
opener.document.forms[0].kk.options[0] = new Option(tmp,tmp);//服务器错
opener.document.forms[0].kk.options[0].text =tmp;
opener.document.forms[0].kk.options[0].value =tmp;
*/
}
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body><button onclick=test()>test</button>
<SCRIPT LANGUAGE="JavaScript">
function test()
{
var options=window.opener.form1.deptsel.options;
window.opener.btnTest_onclick(options[0].value+"mytest",options[1].value+"mytest",2);
}
</SCRIPT>
</body>
</html>
//**************************************************************
<script language=javascript>
function btnTest_onclick(var1,var2,position1){
form1.deptsel.options[position1]=new Option(var1,var2);
} function btnTest2_onclick(){
window.open("test2.html");
}
</script>
<form name=form1>
<table border=1 align=center>
<tr>
<td>
<select name=deptsel>
<option value="value1">value1</option>
<option value="value2">value2</option>
<option value="value3">value3</option>
</select>
</td>
</tr>
</table>
<!--<input type="button" name=btnTest1 value="测 试1" onclick="btnTest_onclick();">-->
<input type="button" name=btnTest2 value="测 试2" onclick="btnTest2_onclick();">
</form>