When binding page data, it is often encountered that the radio setting is selected. The following is the js method I wrote, which can be used after testing. Welcome to Paizhuan
<html> <head> <script type="text/javascript" src="./jquery.min.js"></script></head><body><p> <input id="rdo1" name="rdo1" type="radio" value="1" checked="checked"/>是 <input id="rdo1" name="rdo1" type="radio" value="0"/>否 <button id="btn1">是</button> <button id="btn2">否</button><p><script type="text/javascript"> $(function(){ $("#btn1").click(function(){ $("input[name='rdo1']").eq(0).attr("checked","checked"); $("input[name='rdo1']").eq(1).removeAttr("checked"); $("input[name='rdo1']").eq(0).click(); }); $("#btn2").click(function(){ $("input[name='rdo1']").eq(0).removeAttr("checked"); $("input[name='rdo1']").eq(1).attr("checked","checked"); $("input[name='rdo1']").eq(1).click(); }); });</script></body></html>
The above is the detailed content of Example of how to set radio selection using JavaScript. For more information, please follow other related articles on the PHP Chinese website!