如何在新窗口中控制父窗口中select的值?
从A窗口中弹出B窗口,在B窗口中用JS清除A窗口中一个select中所有的选项目,并给该select添加一个新的选项。如何实现?在网上找的好象都不能用。
------解决方案--------------------改进了一下,这个更灵活,没有投机取巧,哈
A.html
====================================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> Page A </title>
<script language= "JavaScript ">
<!--
function openPageB()
{
window.showModalDialog( "B.html ", document, "dialogHeight:300px; dialogLeft:200px; ");
}
//-->
</script>
</head>
<body>
<input type= "button " onclick= "openPageB(); " value= "Open Page B " />
<select id= "selCar ">
<option value= "1 "> 宝马 </option>
<option value= "2 "> 保时捷 </option>
<option value= "3 "> 奔驰 </option>
</select>
</body>
</html>
B.html
====================================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> Page B </title>
</head>
<body>
<input type= "button " id= "btnClear " value= "Clear ">
</body>
<script language= "JavaScript ">
<!--
var aDocument = window.dialogArguments;
var aSelect = aDocument.getElementById( "selCar ");
var oClear = document.getElementById( "btnClear ");
oClear.onclick = function() {
aSelect.options.length = 0;
var oOption = aDocument.createElement( "OPTION ");
oOption.innerText = "大公共 ";
oOption.value = "0 ";
// 还是 DOM 踏实!
aSelect.appendChild(oOption);
// 死活就是报错?!无厘头
//aSelect.options.add(oOption);
};
//-->
</script>
</html>