我有 3 个单选按钮
<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>
在 jquery 中
$("#test").buttonset();
在那之后,我想禁用它们(当然,禁用放在 if
语句中)
$("#test input").attr("disabled", true); //or
$("#test input").prop("disabled", true);
但它不起作用,按钮仍然可用。
最佳答案
您使用的是 jQuery-UI,将单选按钮更改为 buttonset
后,它们不再影响 UserInterface,因为它包含:
<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>
所以你需要 jQuery UI 函数来禁用“按钮”(它们是 spans
!)
$("#test input").button("disable")
关于javascript - 设置为 buttonset() 后禁用单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10513729/