简体   繁体   中英

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 should be unique..

The checked property is different than the val property .. To uncheck it you have to do this

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

 js_tipologia_pdv.prop('checked', false);

check FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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