jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了这个jquery验证码有什么问题?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
代码应该在页面加载时隐藏文本框,并仅在用户选择“其他”时才显示.

<script type="text/javascript">
        $(document).ready(function () {
        $('#ddlMajor').change(function () {
        if ($(this).val() == 'Other') {
                //                $('#txtOther').show();
         $('#txtOther').css('display','inline');
         }
        else {
                //                $('#txtOther').hide();
        $('#txtOther').css('display','block');
        }

        });

});
</script>

<asp:TextBox runat="server" ID="txtOther" style="display:none;" > </asp:TextBox>

<asp:DropDownList runat="server" ID="ddlMajor">
                 <asp:ListItem Value="AccounTing">AccounTing</asp:ListItem> 
                 <asp:ListItem Value="Management">Management</asp:ListItem>
                 <asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>

解决方法

在使用服务器端控件时,将重新呈现ID.你可以把代码块放在你的javascript中,但我建议你改用一个类:

<asp:TextBox runat="server" ID="txtOther" style="display:none;" CssClass="txtOther"> </asp:TextBox>

<asp:DropDownList runat="server" ID="ddlMajor" CssClass="ddlMajor">
                 <asp:ListItem Value="AccounTing">AccounTing</asp:ListItem> 
                 <asp:ListItem Value="Management">Management</asp:ListItem>
                 <asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>

 $('.ddlMajor').change(function () {
...
});

我也相信你的CSS显示值不正确.试试这个:

$(document).ready(function () {
        $('.ddlMajor').change(function () {
        if ($(this).val() == 'Other') {
         $('.txtOther').css('display','block');
         }
        else {
        $('.txtOther').css('display','none');
        }

        });

或者,如果您不想更改标记,请使用ClientID.注意:这只有在.aspx文件中包含javascript时才有效

$(document).ready(function () {
        $('#<%= ddlMajor.ClientID %>').change(function () {
        if ($(this).val() == 'Other') {
         $('#<%= txtOther.ClientID %>').css('display','block');
         }
        else {
        $('#<%= txtOther.ClientID %>').css('display','none');
        }

        });

大佬总结

以上是大佬教程为你收集整理的这个jquery验证码有什么问题?全部内容,希望文章能够帮你解决这个jquery验证码有什么问题?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。