JS new Option()

来源:百度知道 编辑:UC知道 时间:2024/06/07 00:53:43
在一个页面〔这个页面中有一个<select>和一个文本框〕用window.open(........)打开了一个窗口,在这个窗口中引用window.opener.form1.t1.value="test"可以改变父窗口的文本框内容,但为什么不能给<select>加选项呢,这样写的
window.opener.form1.selectTest.options.add(new Option('a','a'))//我试了好几种方法就是不行,IE提示“服务器出现错误”但在FireFox上正常!这个东西要用IE演示给别人看的,所以一定得在IE上起作用!但我在IE上的父窗口再加一个按钮,点它的事件这样写的“form1.selectTest.options.add(new Option('a','a')”它也能正常加入子选项,为什么在它打开的子窗口中就是不行呢!解决问题了再加分!!

第一个页面:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function addOption(){
    form1.selectTest.options.add(new Option('a','a'));
}
</script>
</head>
<body>

<form id="form1" name="form1">
    <select name="selectTest" id="selectTest"></select>
    <input id="t1" name="t1"/>
</form>

<button onclick="window.open('input.html')">click</button>
</body>
</html>

第二个页面:

<!DOCTYPE html>
<html>
<head&