gpt4 book ai didi

Javascript 子类别 - 3 层

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:50 26 4
gpt4 key购买 nike

我是编程新手,所以如果有更好的方法来做到这一点,我将不胜感激。我搜索了很多小时,但找不到列表中的第三项依赖于前两项的解决方案。

我的目标是让操作系统选项依赖于前两个选择(网络和资源)。有 2 个网络 - 内部网络和防火墙,如果需要,服务器也可以集群。如果选择标准,则可以选择物理或虚拟。如果选择集群,则唯一的选项是物理。

我遇到问题的地方是操作系统的选择。如果选择防火墙和虚拟的组合,则只有 Linux 和 Windows 可用。如果选择防火墙和物理的组合,则允许 AIX、Solaris、Windows 和 Linux。当我单击资源以将其更改为物理资源时,我希望更改操作系统选择。

HTML代码

<div class="left_box">
<body onload="fillCategory();">
<div id ="formWrapper">
<FORM name="drop_list" action="availability.php" method="POST" >
<fieldset>
<label>Network</label>
<SELECT class= "formSelect" NAME="build" onChange="SelectSubCat();" >
<Option value="">Select Internal or Firewall</option>
</SELECT>
<br>
<br>
<label>Resource</label>
<SELECT class= "formSelect" id="resource" NAME="resource">
<Option value="">Resource</option>
</SELECT>
<br>
<br>
<label>OS</label>
<SELECT class= "formSelect" id="OS" NAME="OS">
<Option value="">OS</option>
</SELECT>
<br>
<br>
</fieldset>

Javascript 代码

function fillCategory(){ 
// this function is used to fill the category list on load
addOption(document.drop_list.build, "Internal", "Internal", "");
addOption(document.drop_list.build, "Internal Cluster", "Internal Cluster", "");
addOption(document.drop_list.build, "Firewall", "Firewall", "");
addOption(document.drop_list.build, "Firewall Cluster", "Firewall Cluster", "");
}

function SelectSubCat(){
// ON selection of category this function will work
removeAllOptions(document.drop_list.resource);
removeAllOptions(document.drop_list.OS);

if((document.drop_list.build.value == 'Internal')||(document.drop_list.build.value == 'Firewall')){
addOption(document.drop_list.resource,"Virtual", "Virtual","");
addOption(document.drop_list.resource,"Physical", "Physical","");
}

if((document.drop_list.build.value == 'Internal Cluster') || (document.drop_list.build.value == 'Firewall Cluster')) {
addOption(document.drop_list.resource,"Physical", "Physical");
}

if(document.drop_list.build.value == 'Internal') {
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Standard", "Windows 2008 (64-bit) Standard");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Standard", "Windows 2008 R2 (64-bit) Standard");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Special", "Special");
}

if((document.drop_list.build.value == 'Internal Cluster') ||(document.drop_list.build.value == 'Firewall Cluster')){
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

if((document.drop_list.build.value == 'Firewall') && (document.drop_list.resource.value == 'Virtual')) {
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

if((document.drop_list.build.value == 'Firewall') && (document.drop_list.resource.value == 'Physical')) {
addOption(document.drop_list.OS,"AIX 6.1", "AIX 6.1");
addOption(document.drop_list.OS,"Linux 5.0 (64-bit)", "Linux 5.0 (64-bit)");
addOption(document.drop_list.OS,"Linux 6.0 (64-bit)", "Linux 6.0 (64-bit)");
addOption(document.drop_list.OS,"Solaris 10", "Solaris 10");
addOption(document.drop_list.OS,"Windows 2008 (64-bit) Enterprise", "Windows 2008 (64-bit) Enterprise");
addOption(document.drop_list.OS,"Windows 2008 R2 (64-bit) Enterprise", "Windows 2008 R2 (64-bit) Enterprise");
}

}

//////////////////

function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}


function addOption(selectbox, value, text )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;

selectbox.options.add(optn);
}

最佳答案

将创建操作系统选项的代码部分移至另一个函数。在原始函数的末尾调用它。在资源更改时调用新函数。

喜欢:

function selectResource(){
...
selectOS();

}
function selectOS()...

http://jsfiddle.net/7ey8E/1/

关于Javascript 子类别 - 3 层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13419175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com