Javascript 在文本框长度大于零时,清除列表框并禁用

Javascript 在文本框长度大于零时,清除列表框并禁用,javascript,asp.net,Javascript,Asp.net,在java脚本中,当填充文本框控件时,它是否可能清除我的列表框并禁用它,反之亦然。我正在使用ASP.net C#绑定列表框 <asp:TextBox ID="_tx_Zip" On??? runat="server" Width="197px"></asp:TextBox> <asp:ListBox ID="_lb_Zip" runat="server" Height="82px" SelectionMode="Multiple" Width="200px">

在java脚本中,当填充文本框控件时,它是否可能清除我的列表框并禁用它,反之亦然。我正在使用ASP.net C#绑定列表框

<asp:TextBox ID="_tx_Zip" On??? runat="server" Width="197px"></asp:TextBox>

<asp:ListBox ID="_lb_Zip" runat="server" Height="82px" SelectionMode="Multiple" Width="200px">


我在搞改变了内容的活动,但那不好。抱歉,我正在尝试学习java脚本。

您可以使用javascript的onblur事件,并像

<asp:TextBox ID="_tx_Zip" onblur="update();"

 function update() {
        if (document.getElementById('<%=_tx_Zip.ClientID %>').value != '') {
            document.getElementById('<%=_lb_Zip.ClientID %>').disabled = true;
            document.getElementById("<%= _lb_Zip.clientID %>").options.length = 0;
        }
        else {
            document.getElementById('<%=_lb_Zip.ClientID %>').disabled = false;
        }
    }

谢谢你。。。我使用什么事件重新启用它。这在输入文本时起作用,但是当文本被删除并且我重新关注列表框时,它仍然被禁用?这是:document.getElementById(“”)。options.length=0;完全清除列表框如何将所选索引设置为0?使用document.getElementById(“”)。selectedIndex=0