How to uncheck checked radio button
This question already has an answer here:
This simple script allows you to uncheck an already checked radio button. Works on all javascript enabled browsers.
<html>
<!-- html from your link: [http://jsfiddle.net/wuAWn/][1] -->
<body>
<input type='radio' class='radio-button' name='re'>
<input type='radio' class='radio-button' name='re'>
<input type='radio' class='radio-button' name='re'>
</body>
<script type="text/javascript">
var allRadios = document.getElementsByName('re');
var booRadio;
var x = 0;
for(x = 0; x < allRadios.length; x++){
allRadios[x].onclick = function() {
if(booRadio == this){
this.checked = false;
booRadio = null;
}else{
booRadio = this;
}
};
}
</script>
</html>
http://jsfiddle.net/6Mkde/
Radio buttons are meant to be required options... If you want them to be unchecked, use a checkbox, there is no need to complicate things and allow users to uncheck a radio button; removing the JQuery allows you to select from one of them
You might consider adding an additional radio button to each group labeled 'none' or the like. This can create a consistent user experience without complicating the development process.
链接地址: http://www.djcxy.com/p/12254.html上一篇: 我如何检查jQuery中的多个复选框?
下一篇: 如何取消选中选中的单选按钮