开发者

How to uncheck all radios in a RadioButtonList on the client-side and persist after postback

There is a bug with the ASP .NET Web Forms RadioButtonList - if you uncheck all the radios on the client-side (with javascript), after you do a postback the first item in the list will be selected.

Fo开发者_StackOverflow社区r example, try running the following jquery:

$('#myRadioList input').attr('checked', '');

After you do a postback, the first item in the RadioButtonList will be selected.

Anyone know an elegant work around?


It's because by design you will need to choose one option

To uncheck all:

 $('input[type=radio]').prop('checked', false);

place it to the end of the page or inside

a $(function() {}); or $(document).ready(function() {}); block

P.S. Use prop instead of attr if jQuery 1.6+

.prop() vs .attr()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜