• JavaScript/JQuery radioButton(单选按钮)练习20190409


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script type="text/javascript" src="scripts/jquery-3.3.1.js"></script>
        </head>
        <body>
            
            <div id="checkBoxDiv1">
                测试单选框
                <input type="radio" name="checkBox1" class="checkBox1"><input type="radio" name="checkBox1" class="checkBox1" checked="checked">
            </div>
            
            <script type="text/javascript">
                
                $(".checkBox1").on("click", function(){
                    var i = 0;
                    var parentEle = $(this).parent();
                    var index = $(this).index();
                    $(".checkBox1").each(function(){
                        var currentEle = parentEle.children(".checkBox1:eq(" + i + ")");
                        if(i == index){
                            currentEle.attr("checked", true);
                        }else{
                            currentEle.attr("checked", false);
                        }
                        i++;
                    });
                    i = 0;
                    $(".checkBox1").each(function(){
                        var currentEle = parentEle.children(".checkBox1:eq(" + i + ")");
                        alert(currentEle.attr("checked"));
                        i++;
                    });
                });
                
            </script>
            
        </body>
    </html>

    这个是用来满足特殊需求的勾选一个单选按钮checked设置为true,其他的同name的单选框checked都设置为false.

    2015年10月-2016年3月 总计:5个月.
    2016年11月-2017年6月 总计:7个月.
    2017年7月-2018年4月 总计:9个月.
    2018年5月-2018年5月 总计:1个月.
    2018年6月-2018年12月 总计:6个月.
    2019年1月-2019年12月 总计11个月.
    2020年2月-2021年2月 总计13个月.
    所有总计:5+7+9+1+6+11+13=52个月(4年4个月).
    本人认同二元论.我是理想主义者,现实主义者,乐观主义者,有一定的完美主义倾向.不过,一直都是咸鱼(菜鸟),就算有机会,我也不想咸鱼翻身.(并不矛盾,因为具体情况具体分析)
    英语,高等数学,考研,其他知识学习打卡交流QQ群:946556683
  • 相关阅读:
    31、状态模式(详解版)
    33、中介者模式(详解版)
    36、备忘录模式(详解版)
    34、迭代器模式(详解版)
    30、责任链模式(职责链模式)详解
    29、命令模式(详解版)
    32、观察者模式(Observer模式)详解
    37、解释器模式(详解版)
    35、访问者模式(Visitor模式)详解
    28、策略模式(策略设计模式)详解
  • 原文地址:https://www.cnblogs.com/JimmySeraph/p/10675170.html
Copyright © 2020-2023  润新知