如何取消选择 RadioButton?
How to unselect a RadioButton?
假设我在 RadioButtonGroup 中有一些 RadioButton。我单击其中一个,我意识到我不应该提交表单,相反我只想触发取消操作并将 return 恢复到我选择的 none 的原始状态。我该怎么做?
你可以这样做:
如果这不是答案,请更详细地解释您的问题
$('#ClearAll').on('click',function(){
$('form')[0].reset();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other <br>
<input id="ClearAll" type="button" value="clear">
</form>
想通了。我错误地将值作为 defaultSelected
属性而不是 valueSelected
传递。现在如果需要取消选择,我可以将 null
作为 valueSelected
属性传递。
假设我在 RadioButtonGroup 中有一些 RadioButton。我单击其中一个,我意识到我不应该提交表单,相反我只想触发取消操作并将 return 恢复到我选择的 none 的原始状态。我该怎么做?
你可以这样做:
如果这不是答案,请更详细地解释您的问题
$('#ClearAll').on('click',function(){
$('form')[0].reset();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other <br>
<input id="ClearAll" type="button" value="clear">
</form>
想通了。我错误地将值作为 defaultSelected
属性而不是 valueSelected
传递。现在如果需要取消选择,我可以将 null
作为 valueSelected
属性传递。