选中复选框列表项,然后使用javascript显示下拉列表 [英] checkbox list item selected then show dropdown list visible using javascript

查看:91
本文介绍了选中复选框列表项,然后使用javascript显示下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<asp:CheckBoxList ID="AllowencesCheckbox" runat="server" AutoPostBack="true" "">
                                           <asp:ListItem Text="hi" Value="1"></asp:ListItem>
                                           <asp:ListItem Text="hello" Value="2"></asp:ListItem>
                                       </asp:CheckBoxList>













<asp:DropDownList ID="MileageRateDropDownList" runat="server" 

                                           Visible="false">
                                        </asp:DropDownList>





如果我选择hi,那么使用javascript



here if i select "hi" then MileageRateDropDownListis set to visible true using javascript

推荐答案

将MileageRateDropDownList设置为可见true尝试此代码



代码背后



Try this code

In code behind

protected void Page_Load(object sender, EventArgs e)
    {
        foreach (ListItem item in AllowencesCheckbox.Items)
        {
            if (item.Value == "1")
            {
                item.Attributes.Add("onchange", "Display(document.activeElement.checked);");   
            }
        }
    }







设计中/>







In design


<script type="text/javascript" language="javascript">

        function Display(val) {

            var objDDL = document.getElementById('<%= MileageRateDropDownList.ClientID %>');

            if (val == false) {
                objDDL.style.display = "none";
                objDDL.style.visibility = "hidden";
            }
            else {
                objDDL.style.display = "block";
                objDDL.style.visibility = "visible";
            }
        }
    </script>




<asp:checkboxlist id="AllowencesCheckbox" runat="server" autopostback="false" xmlns:asp="#unknown">
        <asp:listitem text="hi" value="1"></asp:listitem>
        <asp:listitem text="hello" value="2"></asp:listitem>
    </asp:checkboxlist>
    <asp:dropdownlist id="MileageRateDropDownList" runat="server" xmlns:asp="#unknown">
    </asp:dropdownlist>


我会删除Visible =false ddl只管理js方面的可见性(jQuery)



i would remove the Visible="false" of the ddl to manage visibility only js side (jQuery)


document )。ready( function (){
// 隐藏下拉列表
(document).ready(function() { // hide dropdownlist


这篇关于选中复选框列表项,然后使用javascript显示下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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