<form name="frm">
<select name=select1>
</select>
<select name=select2>
</select>
<input name=result>
</form>
<script>
function window.onbeforeunload(){
if(event.clientX>document.body.clientWidth && event.clientY<0||event.altKey)
return;
}
var a2=new Array("Web开发","数据库","我的专家门诊")
var a1=new Array()
a1[0]=new Array("ASP","JSP","PHP","Javascript","CSS");
a1[1]=new Array("Access","SQL Server","Oracle");
a1[2]=new Array("专家分","短信息","得分问题");
function init(){
var arr=new Array()
for(i=0;i<a2.length;i++){
arr[i]="<option value='"+a2[i]+"'>"+a2[i]+"</option>";
}
frm.select1.outerHTML="<select id='select1' onchange='change(this)' >"+arr.join("")+"</select>"
change(frm.select1);
}
init();
function change(src){
var ix=src.selectedIndex;
var ar=new Array()
for(i=0;i<a1[ix].length;i++){
ar[i]="<option value='"+a1[ix][i]+"'>"+a1[ix][i]+"</option>";
}
frm.select2.outerHTML="<select id='select2' onchange='result.value=frm.select1.value+\"+\"+frm.select2.value'>"+ar.join("")+"</select>"
frm.result.value=frm.select1.value+"+"+frm.select2.value;
}
</script>
<select name=select1>
</select>
<select name=select2>
</select>
<input name=result>
</form>
<script>
function window.onbeforeunload(){
if(event.clientX>document.body.clientWidth && event.clientY<0||event.altKey)
return;
}
var a2=new Array("Web开发","数据库","我的专家门诊")
var a1=new Array()
a1[0]=new Array("ASP","JSP","PHP","Javascript","CSS");
a1[1]=new Array("Access","SQL Server","Oracle");
a1[2]=new Array("专家分","短信息","得分问题");
function init(){
var arr=new Array()
for(i=0;i<a2.length;i++){
arr[i]="<option value='"+a2[i]+"'>"+a2[i]+"</option>";
}
frm.select1.outerHTML="<select id='select1' onchange='change(this)' >"+arr.join("")+"</select>"
change(frm.select1);
}
init();
function change(src){
var ix=src.selectedIndex;
var ar=new Array()
for(i=0;i<a1[ix].length;i++){
ar[i]="<option value='"+a1[ix][i]+"'>"+a1[ix][i]+"</option>";
}
frm.select2.outerHTML="<select id='select2' onchange='result.value=frm.select1.value+\"+\"+frm.select2.value'>"+ar.join("")+"</select>"
frm.result.value=frm.select1.value+"+"+frm.select2.value;
}
</script>
<script>
function a(){
var temp = document.createElement("OPTION");
temp.text="4";
temp.value="4";
ss.add(temp);
alert(ss.innerHTML);
}
</script>
<body>
<input type=button onClick="javascript:a();">
<select id="ss"><option>1</option></select>
不好意思,昨天有点事,今天看了一下,你的是把以前的换掉了,这样还要加一个取以前OPTION的步骤,还有没更好的方法。用 innerHTML 又把前面的<OPTION>去掉了,加不上去! DryTry(DT) 的方法也只是在同一页面可行,有 parent 时还是不行。注:我用的是<IFRAME SRC="cm_search.php" ID="brand_left" SCROLLING="no" WIDTH="150" HEIGHT="110" MARGINWIDTH="0" MARGINHEIGHT="0" FRAMEBORDER="0" ALIGN="default"></IFRAME>并且只是在 WIN98下才会出现错误,2K下不会。
In Internet Explore 4.0 it is possible to create a new option in one frame and add it to a select box in another frame. This functionality is not supported in Internet Explorer 5.Using this functionality causes the following Java script error:Object does not support this property or method
It causes the following VBScript error:
Error: Not implemented CAUSE
This was not an intended functionality, which caused some instability. It was removed from Internet Explorer 5. RESOLUTION
There are two ways to work around this. The first way is call Internet Explorer 5's new createElement method on the target frame. The second method is to create a subroutine in the target frame to create the option and then return a reference to it. STATUS
This behavior is by design. MORE INFORMATIONSteps to Reproduce Behavior
The following reproduces the problem and illustrates two workarounds. Note that workaround 1 is Internet Explorer 5 specific.
Place the following frameset code into an HTML page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
<HTML>
<HEAD>
<TITLE>Option Creation Example</TITLE>
</HEAD>
<frameset cols="200,*">
<frame name=left src=left.htm>
<frame name=right src=right.htm>
</frameset>
</HTML> Place the following code into 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> Save the following code as 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> Open Main.htm in the browser.
In the left frame, click the button labeled Reproduce Problem to illustrate the problem.
Again in the left frame, click the two workaround buttons. You will see the two possible workarounds illustrated there.
新概念、新方法先学习。以后再应用。