开发者

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

开发者 https://www.devze.com 2023-03-08 00:47 出处:网络
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.

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

精彩评论

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