How to uncheck a radio button in struts2 using javascript

喜夏-厌秋 提交于 2020-01-05 08:31:43

问题


I have the following radio button. After selecting any radio button, I have a button "CLEAR". On clicking this button, the radio button should be unchecked. Could anyone help me with this? Thanks in advance.

My code:

<s:radio id="isPriTobaccoUsrId" cssClass="hixFieldText" name="testPlanDto.isPriTobaccoUsr" list="#{'Y':'Yes','N':'No'}" />

My javascript:

$('#isPriTobaccoUsrId').attr('checked',false);
$('#isPriTobaccoUsrId').prop('checked',false);
$('#isPriTobaccoUsrId').buttonset('refresh');

I tried these but no luck.

Also tried:

$('#isPriTobaccoUsrId').removeAttr('checked');

回答1:


Struts2 <s:radio> tag gives unique id-s to each generated radio button. So using isPriTobaccoUsrId id is not an option, use class of the element as selector.

$('.hixFieldText').prop('checked', false);



回答2:


$('#isPriTobaccoUsrId').removeAttr('checked');


来源:https://stackoverflow.com/questions/17167178/how-to-uncheck-a-radio-button-in-struts2-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!