Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何根据第三个下拉菜单的选择切换不同的标签(下拉菜单和列表)';什么项目?_Javascript_Vb.net - Fatal编程技术网

Javascript 如何根据第三个下拉菜单的选择切换不同的标签(下拉菜单和列表)';什么项目?

Javascript 如何根据第三个下拉菜单的选择切换不同的标签(下拉菜单和列表)';什么项目?,javascript,vb.net,Javascript,Vb.net,我有2个dropdownlist(假设A和B)和1个listItem(假设C)。我需要在下拉列表(B)和列表项(C)之间切换,这取决于在第一个下拉列表(A)上选择的选项,它只有两个选项。如何使用javascript进行这样的切换 <tr id="trInclude" runat="server"> <td class="label" valign="top">Include : </td> <td valign="to

我有2个dropdownlist(假设A和B)和1个listItem(假设C)。我需要在下拉列表(B)和列表项(C)之间切换,这取决于在第一个下拉列表(A)上选择的选项,它只有两个选项。如何使用javascript进行这样的切换

  <tr id="trInclude" runat="server">
        <td class="label" valign="top">Include : </td>
        <td valign="top">
            <asp:DropDownList ID="ddlExpiring" runat="server" Visible="true"  onchange="reloadDisplayBfys(this.options[this.selectedIndex].value);">
                <asp:ListItem Value="1" Text="Only Expiring"></asp:ListItem>
                <asp:ListItem Value="0" Text="ALL"></asp:ListItem>
            </asp:DropDownList>

            <asp:Label ID="lblFunds" runat="server" Text="Funds" CssClass="label"></asp:Label>
        </td>
    </tr>
    <tr>
        <td class="label" valign="top" width="300">
            <asp:Label ID="lblBFY" runat="server" Text="Expiring budget fiscal year:"></asp:Label></td>
        <td valign="top">
            <asp:ListBox ID="lstBudgetFiscalYear" runat="server" SelectionMode="Multiple" Rows="5" Visible="false">
                <asp:ListItem Text="All" Value="" class="all" />
            </asp:ListBox>
            <asp:DropDownList ID="ddlBudgetFiscalYear" runat="server" Visible="false" onchange="reloadFY(this.options[this.selectedIndex].value);">
                <asp:ListItem Text="All" Value="" class="all"></asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>


 function reloadDisplayBfys(index) {
        var bel = document.getElementById("<%= ddlExpiring.ClientID%>");
        var bfy;
        if (bel.selectedIndex) {
            bfy = bel.options[bel.selectedIndex].value;
        }
        if (bfy == 0) {
            document.getElementById("<%= lstBudgetFiscalYear.ClientID%>").style.display = "block";
            document.getElementById("<%= ddlBudgetFiscalYear.ClientID%>").style.display = "none"; 
        }
        else {
            document.getElementById("<%= lstBudgetFiscalYear.ClientID%>").style.display = "none";
            document.getElementById("<%= ddlBudgetFiscalYear.ClientID%>").style.display = "block";

        }
    }

包括:
函数重载显示bfys(索引){
var bel=document.getElementById(“”);
var-bfy;
如果(贝尔选定索引){
bfy=bel.options[bel.selectedIndex].value;
}
如果(bfy==0){
document.getElementById(“”.style.display=“block”;
document.getElementById(“”.style.display=“无”;
}
否则{
document.getElementById(“”.style.display=“无”;
document.getElementById(“”.style.display=“block”;
}
}

如果asp:DropDownList的工作方式与html
select
元素类似,那么您的值选择器看起来是正确的。使用它的一种方法是跳过“onchange”属性,使用下面代码中的常规事件侦听器


(经过编辑以符合您回复中的规格)
此解决方案使用模板元素存储有条件插入/删除的
lstFiscalYear
选项:

const firstDropdown=document.getElementById(“firstDropdown”),
secondDropdown=document.getElementById(“secondDropdown”);
addEventListener(“更改”,updateDisplay);
函数updateDisplay(事件){
常量isInitialState=Second下拉列表。选项[0]。值==“默认值”,
useInitialState=parseInt(firstDropdown.value)==0;
如果(isInitialState&!useInitialState){
alternativeOption=document.getElementById(“alternativeOptionTemplate”).content.cloneNode(true);
secondDropdown.insertBefore(可选选项,secondDropdown.options[0]);
Second Dropdown.selectedIndex=0;
}
如果(!isInitialState&&useInitialState)为else,则为{
secondDropdown.removeChild(secondDropdown.options[0]);
Second Dropdown.selectedIndex=0;
}
else{/*用户既没有选择0也没有选择1*/}
}

零
一个
上一会计年度的信息
违约

我开始回答,但意识到我不完全理解你的问题。您能否澄清“在下拉列表(B)和列表项(C)之间切换”的含义?您的示例代码中的哪些元素分别表示三个实体dropdown(A)、dropdown(B)和listitem(C)?Hi@Cat,在上面的代码中,“ddlexpiring”表示dropdown(A),“ddlBudgetFiscalYear”表示dropdown(B),“lstBudgetFiscalYear”表示listitem(C)。在这里,如果在“DDLFiring”中选择了值=1,则显示下拉列表“DDLProdgetFiscalYear”,它应该是默认值;否则,如果值=0,则显示列表项“LSTProdgetFiscalYear”。谢谢。我会忙上几个小时,但我有空的时候会再检查。抱歉耽搁了。我更新了答案以满足这些规范(假设您希望在第二个下拉列表中显示自定义选项)