在下拉列表文本框中选择一个项目后无法触发后,请帮助 [英] after selecting an item in dropdownlist text box is not firing please help

查看:73
本文介绍了在下拉列表文本框中选择一个项目后无法触发后,请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function test()
    {
        var index=document.getElementById("DropDownList1").Selectedindex;
        switch(index)
             {
             case 1:
             alert("client1");
               break;
             case 2:
              alert("client2");
               break;
             default:

             }
    }




    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1"  runat="server">
            <asp:ListItem>client1</asp:ListItem>
            <asp:ListItem>client2</asp:ListItem>
        </asp:DropDownList>
        empid<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </div>
    </form>
</body>
</html>


.cs



.cs


protected void Page_Load(object sender, EventArgs e)
   {
       TextBox1.Attributes.Add("onkeypress", "javascript:test()");
   }

推荐答案

如果您希望在下拉单击/选择时调用test(),甚至需要将事件处理程序添加到下拉列表中,而不是文本框如您所添加.

If you want test() to be called on dropdown click/selection even you need to add event handler to dropdown list, not for textbox as u added.

ListBox1.Attributes.Add("onchange", "javascript::test();")


这篇关于在下拉列表文本框中选择一个项目后无法触发后,请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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