无法 select ASP WebForms 控制 jQuery
Cannot select ASP WebForms control with jQuery
我有一个 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 和.rbClosedClient 是asp:Button 中的CssClass。其他 类 是标签。
您是否发现 jQUery 有问题?
添加
ClientId="static"
asp 控件应使 ID 对 JavaScript 可见。这是因为 asp.bet 默认显示生成的 Id。上面的代码将使您能够使用您在标记中提供的 ID。
我有一个 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 和.rbClosedClient 是asp:Button 中的CssClass。其他 类 是标签。 您是否发现 jQUery 有问题?
添加
ClientId="static"
asp 控件应使 ID 对 JavaScript 可见。这是因为 asp.bet 默认显示生成的 Id。上面的代码将使您能够使用您在标记中提供的 ID。