1

I know this has been asked before, but it is not working for my scenario. I have a jquery ui modal form which contains a radiobuttonlist with static values:

    <asp:RadioButtonList ID="rblSlots" runat="server" ViewStateMode="Disabled">
    <asp:ListItem Value="30" enabled="false">30 Minutes</asp:ListItem>
    <asp:ListItem Value="60" enabled="false">1 Hour</asp:ListItem>
    <asp:ListItem Value="90" enabled="false">1 1/2 Hours</asp:ListItem>
    <asp:ListItem Value="120" enabled="false">2 Hours</asp:ListItem>
    <asp:ListItem Value="150" enabled="false">2 1/2 Hours</asp:ListItem>
    <asp:ListItem Value="180" enabled="false">3 Hours</asp:ListItem>
    </asp:RadioButtonList>

Which of course renders as:

    <table id="rblSlots">
    <tr>
    <td><span disabled="disabled"><input id="rblSlots_0" type="radio" name="rblSlots" value="30" disabled="disabled" /><label for="rblSlots_0">30 Minutes</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_1" type="radio" name="rblSlots" value="60" disabled="disabled" /><label for="rblSlots_1">1 Hour</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_2" type="radio" name="rblSlots" value="90" disabled="disabled" /><label for="rblSlots_2">1 1/2 Hours</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_3" type="radio" name="rblSlots" value="120" disabled="disabled" /><label for="rblSlots_3">2 Hours</label></span></td>
    </tr><tr>
    <td><span disabled="disabled"><input id="rblSlots_4" type="radio" name="rblSlots" value="150" disabled="disabled" /><label for="rblSlots_4">2 1/2 Hours</label></span></td>
    </tr><tr>
    ...etc...

in my form opener dialog i make an ajax post to grab some vaues from my webservice among them 'timespan' in the following javascipt, i have set timespan to a static variable for debugging, i want to enable the radio buttons which are <= timespan.

    var strTS = "30,60,90,120,150,180";
    var aryTS = strTS.split(",");
    var timespan = 120;

    for (i = 0; i <= 5; i++) {

        if ($('#rblSlots [value=' + aryTS[i] + ']').val() <= timespan) {

           $('#rblSlots [value=' + aryTS[i] + ']').removeAttr("disabled");

        }
    }

    $("#appointment-form").dialog("open");
    return false;
4

2 回答 2

1

你可以使用prop方法:

$('#rblSlots input[value=' + timespan + ']').prop('disabled', false)

演示

于 2012-07-21T05:34:42.043 回答
0

清除 IE 和 Firefox 中的缓存后,发现上面的代码在 Firefox 中确实可以工作,但由于某种原因它在 IE 中不起作用。所以我放弃了这种方法,因为无论如何都让我看起来更美观。

放弃了表中单选按钮的 RadioButtonList。
给出了唯一的类名和 style='display:none;' 到包含收音机的行。和我的javascript:

    for (i = 0; i <= 5; i++) {
      if (aryTS[i] <= timespan) {
        $(".Slot_" + aryTS[i]).show();
      }
    } 

在 IE 和 Firefox 中运行良好

于 2012-07-23T01:52:55.903 回答