Home > Web Front-end > JS Tutorial > Example of how to set radio selection using JavaScript

Example of how to set radio selection using JavaScript

黄舟
Release: 2017-07-27 14:21:23
Original
3076 people have browsed it

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=&#39;rdo1&#39;]").eq(0).attr("checked","checked");
            $("input[name=&#39;rdo1&#39;]").eq(1).removeAttr("checked");
            $("input[name=&#39;rdo1&#39;]").eq(0).click();
        });
        $("#btn2").click(function(){
            $("input[name=&#39;rdo1&#39;]").eq(0).removeAttr("checked");
            $("input[name=&#39;rdo1&#39;]").eq(1).attr("checked","checked");
            $("input[name=&#39;rdo1&#39;]").eq(1).click();
        });
    });</script></body></html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template