简体   繁体   English

从表格中清除选中的单选按钮值

[英]clear checked radio button value from form

I have this piece of code which represents a few radio buttons. 我有一段代码,代表几个单选按钮。

<label>Tipologia Pdv: </label>
<input type="radio" name="tipologia_pdv" id="tipologia_pdv" value="Iper" style="width:40px;" /><span > Iper</span>
<input type="radio" name="tipologia_pdv" id="tipologia_pdv"
value="Super" style="width:40px;" /><span > Super</span>

Then, i have this code which clears the value, but it doesnt work with radio buttons: 然后,我有清除该值的此代码,但不适用于单选按钮:

  $("#tipologia_pdv").val('');

Now, how would i get the to clear the checked value here? 现在,我将如何在此处清除检查值? I assign the checked value with this and it works: 我为此分配检查值,它可以工作:

var js_tipologia_pdv = $('input:radio[name=tipologia_pdv]:checked').val();
$('#tipologia_pdv').attr('checked', false);

道具也可以

$('#tipologia_pdv').prop('checked', false);
$("#tipologia_pdv").prop("checked", false);

http://api.jquery.com/prop/

I see that the two radio buttons have the same id. 我看到两个单选按钮具有相同的ID。 ID should be unique.. ID应该是唯一的。

The checked property is different than the val property .. To uncheck it you have to do this 该checked属性不同于val属性..要取消选中它,您必须这样做

var js_tipologia_pdv = $('input:radio[name=tipologia_pdv]:checked');

 js_tipologia_pdv.prop('checked', false);

check FIDDLE 检查FIDDLE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM