DropDownList可见的javascript [英] DropDownList visible javascript

查看:71
本文介绍了DropDownList可见的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有一个小问题,我想使用JavaScript显示基于另一个dropdownLists selectedIndex的dropdownlist,而不会引起回发.

Hey guys I have a small problem, I want to display a dropdownlist based on another dropdownLists selectedIndex using Javascript without causing a postback.

function OnLoad() {
      DisplayCarrier(document.getElementById('<%= cboFileType.ClientID %>').selectedValue);
  }


  function DisplayCarrier(value) {
      if (value == 5) {
          document.getElementById('<%= cboCarrier.ClientID %>').visible = true;
       }
   }



我的HTML



My Html

<asp:dropdownlist id="cboFileType" runat="server" CssClass="inputControl" OnSelectedIndexChanged="DisplayCarrier(this.value);" ></asp:dropdownlist>



大家都很感激任何帮助,谢谢大家



Any help is very much apreciated, thanks guys

推荐答案



首先,将您的下拉列表注册为
,该下拉列表将根据在页面加载中选择的第一个下拉列表进行调整 Page.RegisterHiddenField("hdnDropDown",DropDownID.CleintID)

您可以在代码的第一个下拉列表中为dropdownselectedindexchage添加客户端事件,如下所示
DropDownnID.Attributes.Add("onchange","javascript:DropDownChange(this)")

根据您的要求在javascript函数中更改第二个下拉列表的值

功能DropDownChange(value){
//您的条件
document.getElementById(document.getElementById("hdnDropDown").value).value =在第二个下拉列表中要选择的项目的值
}


快乐编码:)
Hi,

First of all register your dropdown which is to be chaged based on the selection of first dropdown in the pageload as
Page.RegisterHiddenField("hdnDropDown", DropDownID.CleintID)

You can add the client side event for the dropdownselectedindexchage for the first dropdown on your code behind as follows
DropDownnID.Attributes.Add("onchange", "javascript:DropDownChange(this)")

Inside the javascript function based on your requirements chage the value of the second dropdown

funtion DropDownChange(value) {
//your conditions
document.getElementById(document.getElementById("hdnDropDown").value).value = The value of the item to be selected in the second dropdown
}


Happy Coding :)


尝试一下.

.aspx页面

Try this out.

.aspx page

<script>
        function DisplayCarrier(value) {

            if (value == 5) {
                document.getElementById('<%= cboCarrier.ClientID %>').style.visibility = 'visible';
            }
            else {
                document.getElementById('<%= cboCarrier.ClientID %>').style.visibility = 'hidden';
            }
        }
    </script>

    <style>
        .hidden { visibility:hidden; }
    </style>

    <asp:dropdownlist id="cboFileType" runat="server" CssClass="inputControl">
        <asp:ListItem Value="1">Item 1</asp:ListItem>
        <asp:ListItem Value="2">Item 2</asp:ListItem>
        <asp:ListItem Value="3">Item 3</asp:ListItem>
        <asp:ListItem Value="4">Item 4</asp:ListItem>
        <asp:ListItem Value="5">Item 5</asp:ListItem>
        <asp:ListItem Value="6">Item 6</asp:ListItem>
        <asp:ListItem Value="7">Item 7</asp:ListItem>
    </asp:dropdownlist>


    <asp:dropdownlist id="cboCarrier" runat="server" CssClass="hidden">
        <asp:ListItem Value="1">Test 1</asp:ListItem>
        <asp:ListItem Value="2">Test 2</asp:ListItem>
        <asp:ListItem Value="3">Test 3</asp:ListItem>
        <asp:ListItem Value="4">Test 4</asp:ListItem>
        <asp:ListItem Value="5">Test 5</asp:ListItem>
        <asp:ListItem Value="6">Test 6</asp:ListItem>
        <asp:ListItem Value="7">Test 7</asp:ListItem>
    </asp:dropdownlist>



aspx.vb页面



aspx.vb page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
       cboFileType.Attributes.Add("onChange", "DisplayCarrier(this.value);")
   End Sub


这篇关于DropDownList可见的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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