提问人:user819774 提问时间:11/3/2023 更新时间:11/4/2023 访问量:21
使用 jquery 禁用 RadioButtonList
RadioButtonList is disable using jquery
问:
我没有弄清楚为什么下面的代码在文本框(id 是 txt1)上工作,而在 radiobuttonlist(id 是 rdl)上不起作用。有人会告诉我怎么做吗?提前致谢。
有jquery:
var chk = $('#chk1');
if (chk.prop('checked')) {
$('#txt1').prop("disabled", false);
$('#rdl').prop("disabled", false);
}
else {
$('#txt').prop("disabled", true);
$('#rdl').prop("disabled", true);
}
aspx 页面上有单选按钮列表
<asp:RadioButtonList ID="rdl" runat="server"/>
答:
0赞
user819774
11/3/2023
#1
在我添加 input[type=radio] 后,它起作用了。
$('#rdl input[type=radio]').prop(“禁用”, false);
0赞
Amin
11/4/2023
#2
发生这种情况的原因是:默认情况下,Web 窗体会借助您提供的 ID 将其自己的 HTML ID 设置为元素(如果您未将其指定为您编写的 ID 相同)。(在呈现时查看网页源代码)
<asp:RadioButtonList ID="rdl" ClientID="static" runat="server"/>
实际上,您拥有的 ,只有在代码隐藏时才可用,如果没有设置为静态。
此外,另一种解决方案是您可以使用 JQuery 的“包含选择器”查询 DOM 元素rdl
$('[id*="rdl"]').prop("disabled", false);
评论