[英]Disable radio button list item with Javascript
I'm attempting to disable a radio button from an asp RadioButtonList using Javascript. 我试图使用Java脚本从ASP RadioButtonList禁用单选按钮。 Here is what I have: 这是我所拥有的:
<asp:RadioButton ID="rbPlanner" runat="server" onclick="deselectRadioListItem('P');" />
which calls this client javascript onClick... 将此客户端称为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. 一切似乎都正常工作(触发,迭代,if语句起作用),但是,即使逻辑被点击,单选按钮控件也不会被禁用。 What am I missing? 我想念什么? Help is much appreciated, thank you! 非常感谢您的帮助,谢谢!
The ===
operator is used for comparison. ===
运算符用于比较。 You need to use =
. 您需要使用=
。
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < '<%= rblSummaryOptions.Items.Count %>'; i++) {
if (document.getElementById(clientID + "_" + i.toString()).value == radioValue) {
document.getElementById(clientID + "_" + i.toString()).disabled = true;
}
else
{
document.getElementById(clientID + "_" + i.toString()).disabled = false;
}
}
}
Or cleaned up a tiny bit: 或清理一点:
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < '<%= rblSummaryOptions.Items.Count %>'; i++) {
var objCurrentRdo = document.getElementById(clientID + "_" + i.toString());
if (objCurrentRdo.value == radioValue)
objCurrentRdo.disabled = true;
else
objCurrentRdo.disabled = false;
}
}
Additional Information: Check out Comparison Operators on MDN. 其他信息:检查出比较操作上MDN。
this is for sure wrong. 这肯定是错误的。
(clientID + "_" + i.toString()).disabled === true;
maybe you won to type 也许你会打字
document.getElementById(clientID + "_" + i.toString()).disabled = true;
or even better 甚至更好
function deselectRadioListItem(radioValue) {
var clientID = ('<%= rblSummaryOptions.ClientID %>');
for (i = 0; i < <%= rblSummaryOptions.Items.Count %>; i++) {
document.getElementById(clientID + "_" + i).disabled =
document.getElementById(clientID + "_" + i).value == radioValue;
}
}
you have some bugs here... 你这里有一些错误...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.