【问题标题】:Cannot select ASP WebForms control with jQuery无法使用 jQuery 选择 ASP WebForms 控件
【发布时间】:2015-03-06 16:26:03
【问题描述】:

我有一个 asp:RadioButton 并尝试根据标签是否被选中来操作它。使用此代码:

       if ($('.rbOpenClient').prop('checked'))
            $('.openInvLabel').addClass('radioBtnSelected');
        else if ($('rbClosedClient').prop('checked'))
            $('.closedInvLabel').addClass('radioBtnSelected');

        $('.openInvLabel').click(function () {
            $('.rbOpenClient').css('checked', true);
            $('.openInvLabel').addClass('radioBtnSelected');

            $('.rbClosedClient').css('checked', false);
            $('.closedInvLabel').removeClass('radioBtnSelected');
        });

        $('.closedInvLabel').click(function () {
            $('.rbClosedClient').prop('checked', true);
            $('.closedInvLabel').addClass('radioBtnSelected');

            $('.rbClosedClient').prop('checked', false);
            $('.openInvLabel').removeClass('radioBtnSelected');
        });

.rbOpenClient 和 .rbClos​​edClient 是 asp:Button 中的 CssClass。其他类是标签。 您是否发现 jQUery 存在一些问题?

【问题讨论】:

    标签: javascript c# jquery asp.net webforms


    【解决方案1】:

    添加

    ClientId="静态"

    到 asp 控件应该使 id 对 JavaScript 可见。这是因为 asp.bet 默认显示生成的 Id。上面的代码将使您能够使用您在标记中提供的 id。

    【讨论】:

    • @ivan mihov,我的回答有帮助吗?如果是,请标记答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-14
    • 2015-11-04
    相关资源
    最近更新 更多