使用 JavaScript 禁用单选按钮列表项
我正在尝试使用 JavaScript 从 asp RadioButtonList
禁用单选按钮。这是我所拥有的:
<asp:RadioButton ID="rbPlanner" runat="server" onclick="deselectRadioListItem('P');" />
它调用此客户端 JavaScript onClick
...
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < '<%= rblSummaryOptions.Items.Count %>'; i++) {
if (document.getElementById(clientID + "_" + i.toString()).value == radioValue) {
(clientID + "_" + i.toString()).disabled === true;
}
else
{
(clientID + "_" + i.toString()).disabled === false;
}
}
}
一切似乎都工作正常(触发、迭代、if 语句工作),但是单选按钮控件并未被禁用,即使逻辑被击中。我缺少什么?非常感谢帮助!
I'm attempting to disable a radio button from an asp RadioButtonList
using JavaScript. Here is what I have:
<asp:RadioButton ID="rbPlanner" runat="server" onclick="deselectRadioListItem('P');" />
which calls this client JavaScript onClick
...
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < '<%= rblSummaryOptions.Items.Count %>'; i++) {
if (document.getElementById(clientID + "_" + i.toString()).value == radioValue) {
(clientID + "_" + i.toString()).disabled === true;
}
else
{
(clientID + "_" + i.toString()).disabled === false;
}
}
}
Everything appears to be working correctly (fires, iterates, if-statements work) however, the radiobutton control is not becoming disabled, even though the logic is hit. What am I missing? Help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
===
运算符用于比较。您需要使用=
。或者清理一点:
其他信息:查看 MDN 上的比较运算符。
The
===
operator is used for comparison. You need to use=
.Or cleaned up a tiny bit:
Additional Information: Check out Comparison Operators on MDN.
这肯定是错误的。
也许你不会打字
,或者更好的
是你这里有一些错误......
this is for sure wrong.
maybe you won to type
or even better
you have some bugs here...