动态下拉菜单(第2部分)...... [英] dynamic drop down menu (part 2)...

查看:71
本文介绍了动态下拉菜单(第2部分)......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继我早些时候的帖子之后,我发现了一些东西,其中包括我正在做的部分

,但有两个问题:


1)脚本中存在错误。作为一个Javascript新手,我没有

想知道问题是什么。


2)我不知道如何重新编程脚本,以便打开一个URL

,具体取决于所做的选择。


这是代码(感谢Google!),我会感激任何帮助你可以

给。


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 3.2 Final // EN">

< HTML>

< HEAD>

< TITLE>动态下拉框< / TITLE>

< META NAME =" Generator" CONTENT =" TextPad 3.0"

< META NAME =" Author" CONTENT =" Heidi Housten"

< / HEAD>

< style>

body,table,td {font-家庭:宋体; font-size:9pt}

select {width:130; font-family:verdana}

pre {font-size:9pt}

< / style>


< script language = javascript>

<! -

mainOpt = new Array( )

subOpt = new Array()

mainOpt [0] =" How to relax"

subOpt [0] = new Array( "","","")

mainOpt [1] =" Hot Spots"

subOpt [1] = new Array(" ;选择热点,Mojave,火星,死亡

谷,Mt.St。Helens)

mainOpt [ 2] =节日

subOpt [2] =新阵列(哪一个?,Mardi Gras,Cinco de

Mayo ;,仲夏,风筝节)

mainOpt [3] =好书

subOpt [3] =新数组(" Book?",N is for Noose,4 to

Score,A Grave Talent和A Grave Talent。 ,Six of One)

mainOpt [4] =" Holidays"

subOpt [4] = new Array(" Choose

Holiday",Cruises,Safaris,Ballooning,Adventu res)

函数init()

{


fillCombo(document.forms.myMenus.mainMenu,mainOpt)

fillCombo(document.forms.myMenus.mainBox,mainOpt)

}


函数fillCombo(cmbBox,aryMenu)

{

cmbBox.length = 0 //清除当前选项

for(menuApt in aryMenu)

{

cmbBox.options [cmbBox.length] = new

Option(aryMenu) [menuOpt],cmbBox.length)

}

//显示第一项如果是下拉菜单

cmbBox.selectedIndex = 0 < br $>
}

// - >

< / script>


< BODY BGCOLOR = QUOT;#FFFFFF" TEXT = QUOT;#000000" LINK = QUOT;#FF0000" onload =" init()">

< center>

< form name = myMenus>

< br>一个例子< br>< br>

<! - 为旧浏览器选择模板,一些

不能动态改变大小 - >

< select name = mainMenu

onchange =" fillCombo(subMenu,subOpt [this.selectedIndex])">

<选项>

<选项>

<选项>

<选项>

< option>

< option>& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; & nbsp;& nbsp;

< / select>< br>< br>

< select name = subMenu>

< option>

< option>

< option>

< option>

< option>

< option>& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; & nbsp;& nbsp;

< / select>

< br>

< / form>

< / center>

< / BODY>

< / HTML>

Further to my earlier post, I''ve found something that does partly what
I''m doing, but there are two issues:

1) There is an error in the script. Being a Javascript newbie, I''ve no
idea what the problem is.

2) I don''t know how to re-program the script so that it opens up a url
depending on the choices made.

Here is the code (thanks Google!), I''d appreciate any help the you can
give.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Dynamic Dropdown Boxes</TITLE>
<META NAME="Generator" CONTENT="TextPad 3.0">
<META NAME="Author" CONTENT="Heidi Housten">
</HEAD>
<style>
body,table,td {font-family:verdana; font-size:9pt}
select {width:130;font-family:verdana}
pre { font-size:9pt }
</style>

<script language=javascript>
<!--
mainOpt = new Array()
subOpt = new Array()
mainOpt[0] = "How to relax"
subOpt [0] = new Array("","","")
mainOpt[1] = "Hot Spots"
subOpt [1] = new Array("Pick a Hot Spot","Mojave","Mars","Death
Valley","Mt. St. Helens")
mainOpt[2] = "Festivals"
subOpt [2] = new Array("Which One?","Mardi Gras","Cinco de
Mayo","Midsummer","Kite Festival")
mainOpt[3] = "Good Books"
subOpt [3] = new Array("Which Book?","N is for Noose","Four to
Score","A Grave Talent","Six of One")
mainOpt[4] = "Holidays"
subOpt [4] = new Array("Choose
Holiday","Cruises","Safaris","Ballooning","Adventu res")
function init()
{

fillCombo(document.forms.myMenus.mainMenu,mainOpt)
fillCombo(document.forms.myMenus.mainBox,mainOpt)
}

function fillCombo(cmbBox,aryMenu)
{
cmbBox.length = 0 // Clear out the current options
for (menuOpt in aryMenu)
{
cmbBox.options[cmbBox.length] = new
Option(aryMenu[menuOpt],cmbBox.length)
}
//Show first item if it is a drop down
cmbBox.selectedIndex=0
}
//-->
</script>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" onload="init()">
<center>
<form name=myMenus>
<br>an example<br><br>
<!-- do select template for older browsers, some
can''t change size dynamically -->
<select name=mainMenu
onchange="fillCombo(subMenu,subOpt[this.selectedIndex])">
<option>
<option>
<option>
<option>
<option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
</select><br><br>
<select name=subMenu>
<option>
<option>
<option>
<option>
<option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
</select>
<br>
</form>
</center>
</BODY>
</HTML>

推荐答案

fi *********** @ gmail。 com 写道:
fi***********@gmail.com wrote:
这是代码(感谢Google!),我将非常感谢您给予的任何帮助。


我不做JavaScript,但我们在这里...

< style>
body,table, td {font-family:verdana; font-size:9pt}
select {width:130; font-family:verdana}
pre {font-size:9pt}
< / style>
Here is the code (thanks Google!), I''d appreciate any help the you can
give.
I don''t do JavaScript, but while we''re here...
<style>
body,table,td {font-family:verdana; font-size:9pt}
select {width:130;font-family:verdana}
pre { font-size:9pt }
</style>




9pt?积分用于印刷。许多人无法阅读,

并且可能无法在某些浏览器中调整大小。将字体大小设置为

100%。

http://www.xs4all.nl/~sbpoley/webmatters/fontsize.html
http://www.xs4all.nl/~sbpoley/webmatters/verdana.html

-

-bts

-警告:我为草坪鹿刹车



9pt? Points are for printing. Many people won''t be able to read that,
and may not be able to resize it in some browsers. Set your font-size to
100%.

http://www.xs4all.nl/~sbpoley/webmatters/fontsize.html
http://www.xs4all.nl/~sbpoley/webmatters/verdana.html

--
-bts
-Warning: I brake for lawn deer


fi *********** @ gmail.com 写道:
继我之前的帖子之后,我发现了一些部分内容正在做什么,但有两个问题:



你没有得到令人满意的回应的原因是,大多数人认为你正在尝试的是一个坏主意。但是在

JavaScript的问题上(必须启用表单才能工作,另一个不好的想法)你有一些明显的错误,我会告诉你,教育

和所有。
1)脚本中有错误。作为一个Javascript新手,我不知道问题是什么。

2)我不知道如何重新编写脚本以便打开一个网址
取决于所做出的选择。

这是代码(感谢Google!),我将非常感谢您给予的任何帮助。

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 3.2 Final // EN">


呃,请查看doctype。这很古老。 < HTML>
< HEAD>
< TITLE>动态下拉框< / TITLE>
< META NAME =" Generator" CONTENT =" TextPad 3.0"
< META NAME =" Author" CONTENT =" Heidi Housten"
< / HEAD>

< style>
body,table,td {font-family:verdana; font-size:9pt}
选择{width:130; font-family:verdana}
pre {font-size:9pt}
< / style>


接下来虽然结束带有'';''的JavaScript语句是可选的我

推荐它,因为它可以防止单个语句跨越时的错误

比在线更多。你也可以在

单行上发表不止一个声明:

var aOpt = new Array; var oMine = new Object;

< script language = javascript>
<! -
mainOpt = new Array()
subOpt = new Array()
mainOpt [0] ="如何放松
subOpt [0] = new Array(",quot;","")
mainOpt [1] =热点subOpt [1] =新阵列(Pick a Hot Spot,Mojave,Mars,Death
Valley,Mt. St. Helens")
mainOpt [2] =" Festivals"
subOpt [2] = new Array(Which One?,Mardi Gras,Cinco de
Mayo,仲夏,风筝节)
mainOpt [3] =好书
subOpt [3] =新数组(哪本书?, N代表绞索,四代代表评分,严重天赋,六分之一)
mainOpt [4] =假期
subOpt [4] = new Array(选择
Holiday,Cruises,Safaris,Ball ooning",Adventu res)
函数init()
{/>
fillCombo(document.forms.myMenus.mainMenu,mainOpt)
fillCombo(文档。 forms.myMenus.mainBox,mainOpt)
这里不正确------------------------- ^^ ------ ^^^

应该是:


fillCombo(document.forms.myMenus.subMenu,subOpt [0]);


填充第二个SELECTsubMenu使用第一阵列subOpt [0]在

初始化。


}

函数fillCombo(cmbBox,aryMenu)
{/ cmbBox。 length = 0 //清除当前选项
(aryMenu中的menuOpt)
{
cmbBox.options [cmbBox.length] = new
选项(aryMenu [menuOpt], cmbBox.length)
//显示第一项如果是下拉菜单
cmbBox.selectedIndex = 0
}
// - >
< / script>
< BODY BGCOLOR =" #FFFFFF" TEXT = QUOT;#000000" LINK = QUOT;#FF0000" onload =" init()">
< center>
< form name = myMenus>
< br>示例< br>< br>
<! - 为旧浏览器选择模板,有些
无法动态改变大小 - >
< select name = mainMenu
onchange =" fillCombo(subMenu) ,子选项[this.selectedIndex])">
------------------------- ^^^

应该传递对SELECT对象的完整引用:


onchange =" fillCombo(this.form.subMenu,subOpt [this.selectedIndex]);

< option>
<选项>
<选项>
<选项>
<选项>
<选项>& nbsp;& nbsp;& nbsp;& nbsp; &安培; NBSP;&安培; NBSP;&安培; NBSP; & nbsp;& nbsp;
< / select>< br>< br>
< select name = subMenu>
< option>
<选项>
<选项>
<选项>
<选项>
<选项>& nbsp;& nbsp;& nbsp;& nbsp; &安培; NBSP;&安培; NBSP;&安培; NBSP; & nbsp;& nbsp;
< / select>
< br>
< / form>
< / center>
< / BODY>
< / HTML>
Further to my earlier post, I''ve found something that does partly what
I''m doing, but there are two issues:

The reason you did not get a satifactory response is that most feel that
what your are attempting is a ''bad idea''. But in the matter of
JavaScript (which must be enabled for the form to work, the other bad
idea) you have some obvious errors which I will show to you, educational
and all.
1) There is an error in the script. Being a Javascript newbie, I''ve no
idea what the problem is.

2) I don''t know how to re-program the script so that it opens up a url
depending on the choices made.

Here is the code (thanks Google!), I''d appreciate any help the you can
give.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
Ugh, please look up doctype. This is ancient. <HTML>
<HEAD>
<TITLE>Dynamic Dropdown Boxes</TITLE>
<META NAME="Generator" CONTENT="TextPad 3.0">
<META NAME="Author" CONTENT="Heidi Housten">
</HEAD>
<style>
body,table,td {font-family:verdana; font-size:9pt}
select {width:130;font-family:verdana}
pre { font-size:9pt }
</style>


Next although ending JavaScript statements with a '';'' is optional I
recommend it because is prevents errors when a single statement spans
more than on line. Also your can gang more than one statement on a
single line:
var aOpt=new Array; var oMine=new Object;

<script language=javascript>
<!--
mainOpt = new Array()
subOpt = new Array()
mainOpt[0] = "How to relax"
subOpt [0] = new Array("","","")
mainOpt[1] = "Hot Spots"
subOpt [1] = new Array("Pick a Hot Spot","Mojave","Mars","Death
Valley","Mt. St. Helens")
mainOpt[2] = "Festivals"
subOpt [2] = new Array("Which One?","Mardi Gras","Cinco de
Mayo","Midsummer","Kite Festival")
mainOpt[3] = "Good Books"
subOpt [3] = new Array("Which Book?","N is for Noose","Four to
Score","A Grave Talent","Six of One")
mainOpt[4] = "Holidays"
subOpt [4] = new Array("Choose
Holiday","Cruises","Safaris","Ballooning","Adventu res")
function init()
{

fillCombo(document.forms.myMenus.mainMenu,mainOpt)
fillCombo(document.forms.myMenus.mainBox,mainOpt) Incorrect here-------------------------^^------^^^
should be:

fillCombo(document.forms.myMenus.subMenu,subOpt[0]);

to fill the second SELECT "subMenu" with the 1st array "subOpt[0]" upon
initialization.

}

function fillCombo(cmbBox,aryMenu)
{
cmbBox.length = 0 // Clear out the current options
for (menuOpt in aryMenu)
{
cmbBox.options[cmbBox.length] = new
Option(aryMenu[menuOpt],cmbBox.length)
}
//Show first item if it is a drop down
cmbBox.selectedIndex=0
}
//-->
</script>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" onload="init()">
<center>
<form name=myMenus>
<br>an example<br><br>
<!-- do select template for older browsers, some
can''t change size dynamically -->
<select name=mainMenu
onchange="fillCombo(subMenu,subOpt[this.selectedIndex])"> -------------------------^^^
should pass the complete reference to the SELECT object:

onchange="fillCombo(this.form.subMenu, subOpt[this.selectedIndex]);
<option>
<option>
<option>
<option>
<option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
</select><br><br>
<select name=subMenu>
<option>
<option>
<option>
<option>
<option>
<option>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
</select>
<br>
</form>
</center>
</BODY>
</HTML>




可能更多,但这是我在快速检查时发现的。


-

保重,


Jonathan

--------------- ----

LITTLE WORKS STUDIO
http:// www .LittleWorksStudio.com




" Beauregard T. Shagnasty" <一个********* @ example.invalid>。在留言中写道

news:Re ******************* @ bgtnsc04-news.ops.worldnet.att.net ...

"Beauregard T. Shagnasty" <a.*********@example.invalid> wrote in message
news:Re*******************@bgtnsc04-news.ops.worldnet.att.net...
fi *********** @ gmail.com 写道:
fi***********@gmail.com wrote:
这是代码(感谢Google!),我将非常感谢您给予的任何帮助。
Here is the code (thanks Google!), I''d appreciate any help the you can
give.


<我不做JavaScript,但我们在这里......



I don''t do JavaScript, but while we''re here...

< style>
body,table,td {font-family :宋体; font-size:9pt}
select {width:130; font-family:verdana}
pre {font-size:9pt}
< / style>
<style>
body,table,td {font-family:verdana; font-size:9pt}
select {width:130;font-family:verdana}
pre { font-size:9pt }
</style>


9pt?积分用于印刷。许多人无法阅读,
并且可能无法在某些浏览器中调整它。将字体大小设置为
100%。

http://www.xs4all.nl/~sbpoley/webmatters/fontsize.html
http://www.xs4all.nl/~sbpoley/webmatters/verdana.html



< snip>


感谢您的评论。同样,这与我的项目无关。如果这个

是用于正确的网站(如进入WWW,并使用

跨浏览器,然后是,我同意)。


感谢您的支持评论。

-

Neil


<snip>

Thanks for your comments. Again, this is not relevent to my project. If this
was for a "proper" website (as in to go on the WWW, and be used
cross-browser, then yes, I''d agree).

Thanks for your comments.
--
Neil


这篇关于动态下拉菜单(第2部分)......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆