说明:以上的方法在IE5里有时不能实现,是因为IE5去除了此功能!!!看看下面的代码是否在你的IE里能否正常工作!!! ===============================================================================***************** 例子.htm ******************<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN"> <HTML> <HEAD> <TITLE></TITLE> </HEAD> <frameset cols="200,*"> <frame name=left src=left.htm> <frame name=right src=right.htm> </frameset> </HTML> **************** left.htm ****************** <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN"> <HTML> <HEAD> <TITLE>Left Hand frame</TITLE><script language=javascript> var rFrame; var rFrameDoc; var rForm;//------------ getFrame() //------------ Get references to objects in right frame function getFrame() { rFrame = parent.right; rFrameDoc = rFrame.document; rForm = rFrameDoc.testForm; }//------------ failOpt() //------------ Reproduces failure function failOpt(elName,inText,inValue) { //Get a reference to select box in the other frame var rSel = rForm(elName);//Create a new Option in this frame var myOpt = new Option(inText,inValue)//add option from this frame to select box in other frame alert("Check the select box to see if any item was added."); rSel.options[rSel.length] = myOpt; }//------------ addOpt() //------------ Workaround 1 //------------ Does not require changes to right hand frame function addopt(elName,inText,inValue) { //Solution for Internet Explorer 5+ Only var rSel = rForm(elName);//Use method on other frame to create option, returns a reference var oOption = rFrameDoc.createElement("OPTION");//set properties oOption.text=inText; oOption.value=inValue;//add option to select box in other frame rSel.options[rSel.length] = oOption; // prompt user to open the select box in the other frame to see the item alert("Check the select box to see if any item was added.");} //------------ otherOpt() //------------ Workaround 2 //------------ Requires function in right hand frame too function otherOpt(elName,inText,inValue) { var rSel = rForm(elName);//Call a function in the other frame that returns //a reference to a new option var oOption = rFrame.newOpt(inText,inValue);//Add option to select box in other frame rSel.options[rSel.length] = oOption; // prompt user to open the select box in the other frame to see the item alert("Check the select box to see if any item was added."); } </script> </HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" onload="getFrame()"> Internet Explorer 5 cannot add an option created in this frame, to a select box <BR>across frames. Internet Explorer 4 does. <BR><BR/> <BR> type your option text if you like<BR/><input type=text value="Option Text" name=optText><BR><BR><input type=button name=trigger1 value="Reproduce Problem" onclick="failOpt( 'mainMenu',optText.value,optText.value );"> <BR><BR><input type=button name=trigger1 value="Workaround 1" onclick="addopt( 'mainMenu',optText.value,optText.value );"> <BR><BR><input type=button name=trigger2 value="Workaround 2" onclick="otherOpt( 'mainMenu',optText.value,optText.value );"> <BR><BR></BODY> </HTML> ************* right.htm ***************** <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN"> <HTML> <HEAD> <TITLE>Right Hand frame</TITLE><script language=javascript>//------------ newOpt() //------------ This function is only for workaround #2 //------------ Creates a new Option and returns reference function newOpt(inText,inValue) { // Create element in this frame's tree var myOpt = new Option(inText,inValue)// return reference return myOpt }</script> </HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000"> <form name="testForm"> Use input form in left hand frame to update this select box <BR><BR> <select name="mainMenu"> <option>Some Options</option> </select></form> </BODY></HTML>
===============================================================================***************** 例子.htm ******************<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<frameset cols="200,*">
<frame name=left src=left.htm>
<frame name=right src=right.htm>
</frameset>
</HTML> **************** left.htm ******************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
<HTML>
<HEAD>
<TITLE>Left Hand frame</TITLE><script language=javascript>
var rFrame;
var rFrameDoc;
var rForm;//------------ getFrame()
//------------ Get references to objects in right frame
function getFrame()
{
rFrame = parent.right;
rFrameDoc = rFrame.document;
rForm = rFrameDoc.testForm;
}//------------ failOpt()
//------------ Reproduces failure
function failOpt(elName,inText,inValue)
{
//Get a reference to select box in the other frame
var rSel = rForm(elName);//Create a new Option in this frame
var myOpt = new Option(inText,inValue)//add option from this frame to select box in other frame
alert("Check the select box to see if any item was added.");
rSel.options[rSel.length] = myOpt;
}//------------ addOpt()
//------------ Workaround 1
//------------ Does not require changes to right hand frame
function addopt(elName,inText,inValue)
{
//Solution for Internet Explorer 5+ Only var rSel = rForm(elName);//Use method on other frame to create option, returns a reference
var oOption = rFrameDoc.createElement("OPTION");//set properties
oOption.text=inText;
oOption.value=inValue;//add option to select box in other frame
rSel.options[rSel.length] = oOption;
// prompt user to open the select box in the other frame to see the item
alert("Check the select box to see if any item was added.");} //------------ otherOpt()
//------------ Workaround 2
//------------ Requires function in right hand frame too
function otherOpt(elName,inText,inValue)
{
var rSel = rForm(elName);//Call a function in the other frame that returns
//a reference to a new option
var oOption = rFrame.newOpt(inText,inValue);//Add option to select box in other frame
rSel.options[rSel.length] = oOption;
// prompt user to open the select box in the other frame to see the item
alert("Check the select box to see if any item was added.");
}
</script>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" onload="getFrame()">
Internet Explorer 5 cannot add an option created in this frame, to a select box
<BR>across frames. Internet Explorer 4 does.
<BR><BR/>
<BR> type your option text if you like<BR/><input type=text value="Option Text" name=optText><BR><BR><input type=button name=trigger1 value="Reproduce Problem"
onclick="failOpt( 'mainMenu',optText.value,optText.value );">
<BR><BR><input type=button name=trigger1 value="Workaround 1"
onclick="addopt( 'mainMenu',optText.value,optText.value );">
<BR><BR><input type=button name=trigger2 value="Workaround 2"
onclick="otherOpt( 'mainMenu',optText.value,optText.value );">
<BR><BR></BODY>
</HTML> ************* right.htm *****************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
<HTML>
<HEAD>
<TITLE>Right Hand frame</TITLE><script language=javascript>//------------ newOpt()
//------------ This function is only for workaround #2
//------------ Creates a new Option and returns reference
function newOpt(inText,inValue)
{
// Create element in this frame's tree
var myOpt = new Option(inText,inValue)// return reference
return myOpt
}</script>
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000">
<form name="testForm">
Use input form in left hand frame to update this select box
<BR><BR>
<select name="mainMenu">
<option>Some Options</option>
</select></form>
</BODY></HTML>