opener.document.formName.seelctName.options.length=0
opener.document.formName.seelctName.options[opener.document.formName.seelctName.options.length] = new Option("v","t")试试
opener.document.formName.seelctName.options[opener.document.formName.seelctName.options.length] = new Option("v","t")试试
window.parent.document.formName.seelctName.add(new Option("v","t"));
注意不要清空,留一个,否则就会因为不是同一 document 对象而无法添加。A.html
====================================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Page A</title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script language="JavaScript">
<!--
function openPageB()
{
var eleSelect = document.getElementById("selCar");
window.showModalDialog("B.html", eleSelect, "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>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<input type="button" id="btnClear" value="Clear">
</body>
<script language="JavaScript">
<!--
var oSelect = window.dialogArguments;
var oClear = document.getElementById("btnClear");
oClear.onclick = function() {
oSelect.options.length = 1;
oSelect.options[0].innerText = "大公共";
oSelect.options[0].value = "0";
};
//-->
</script>
</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>