Javascript 设置为buttonset()后禁用单选按钮
我有三个单选按钮Javascript 设置为buttonset()后禁用单选按钮,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,我有三个单选按钮 <div id="test"> <input type="radio" id="time1" name="radio" value="1" /><label for="time1">Test 1</label> <input type="radio" id="time2" name="radio" value="2" /><label for="time2">Test 2</label> <
<div id="test">
<input type="radio" id="time1" name="radio" value="1" /><label for="time1">Test 1</label>
<input type="radio" id="time2" name="radio" value="2" /><label for="time2">Test 2</label>
<input type="radio" id="time3" name="radio" value="3" /><label for="time3">Test 3</label>
</div>
之后,我想用禁用它们(当然,禁用放在if
语句中)
但它不起作用,按钮仍处于启用状态
$("#test > input:radio").button({disabled:true});
您使用的是jQuery UI,将单选按钮更改为
按钮设置后,它们不再影响用户界面,因为它包装为:
<div id="test" class="ui-buttonset">
<input type="radio" id="time1" name="radio" value="1" class="ui-helper-hidden-accessible"><label for="time1" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false"><span class="ui-button-text">Test 1</span></label>
<input type="radio" id="time2" name="radio" value="2" class="ui-helper-hidden-accessible"><label for="time2" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Test 2</span></label>
<input type="radio" id="time3" name="radio" value="3" class="ui-helper-hidden-accessible"><label for="time3" aria-pressed="true" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-state-active" role="button" aria-disabled="false"><span class="ui-button-text">Test 3</span></label>
</div>
再次禁用调用$(“#test”).buttonset()后
然后:
我测试它并为我工作正确的方法是:
$('#test')。按钮集('option','disabled',true)。按钮集('refresh')
我无法让任何其他建议发挥作用。这一个对我来说是这样的。我使用的方法是(无线组ID是buttonset ID):
现在,假设您想将其中一个单选按钮设置为选中,触发一个可能已编程为相关单选按钮的单击事件,然后禁用,您可以按如下方式链接所有这些:
$('#RadioButtonID').prop('checked',true).trigger('click').parent().buttonset('disable').buttonset('refresh');
您的标记缺少最后一个字母。@MichaelSwan检查我的演示链接,它似乎是因为$.buttonset()而发生的。禁用单选后,再次调用“$”(“#测试输入”).prop(“禁用”,true);但它不起作用,按钮仍处于启用状态。“你只是复制了他不起作用的代码……看起来你复制了答案。”(@gdoron我不复制答案,我认为这不是一个复制/粘贴练习的地方。:(这是一个非常昂贵的操作,您应该使用jQuery UI本机功能。您可以在我的答案中看到按钮集函数的功能。。。
<div id="test" class="ui-buttonset">
<input type="radio" id="time1" name="radio" value="1" class="ui-helper-hidden-accessible"><label for="time1" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" role="button" aria-disabled="false"><span class="ui-button-text">Test 1</span></label>
<input type="radio" id="time2" name="radio" value="2" class="ui-helper-hidden-accessible"><label for="time2" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Test 2</span></label>
<input type="radio" id="time3" name="radio" value="3" class="ui-helper-hidden-accessible"><label for="time3" aria-pressed="true" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right ui-state-active" role="button" aria-disabled="false"><span class="ui-button-text">Test 3</span></label>
</div>
$("#test input").button("disable")
$("#test").buttonset();
$("#test input").attr("disabled", true); //or
$("#test input").prop("disabled", true);
$("#test").buttonset();
$('#RadioGroupID').buttonset('disable').buttonset('refresh');
$('#RadioButtonID').prop('checked',true).trigger('click').parent().buttonset('disable').buttonset('refresh');