是否有可能使单选按钮“不可点击”/“不可选”而不“禁用”它?
出于美学原因,我需要知道这是否可能以及如何实现.
目前的代码如下:
<input name='example' value='1' type='radio'/> <input name='example' value='2' checked='checked' type='radio'/> <input name='example' value='3' type='radio'/> <input name='example' value='4' type='radio'/> <input name='example' value='5' type='radio'/>
解决方法
要在不使用禁用的情况下保留无线电输入的已检查/未检查状态(这会更简单),您可以使用以下命令:
// select the relevant radio input elements: $('input[name="example"]') // bind a change-event handler using 'on()': .on('change',function(){ // re-select the same elements: $('input[name="example"]') // set the 'checked' property back to the default (on page-load) state: .prop('checked',function(){ return this.defaultChecked; }); });
参考文献:
> Attribute-equals ([attribute="value"]
) selector.
> on()
.
> prop()
.