• JQuery 获取多选框的值


    JQuery 获取多选框的值

        <input type="checkbox" name="test" value="1"  id="a"><input type="checkbox" name="test" value="2" id="b"><input type="checkbox" name="test" value="3" id="c"><input type="checkbox" name="test" value="4" id="d"><input type="button" value="确定" onClick="CodeCheck()" />
        <input type="button" value="确定2" onClick="CodeCheck2()" />
        function CodeCheck1() {
            
                var arry = new Array();
                //循环所有选中的值
            $('input[name="test"]:checked').each(function (index, element) {
                    //追加到数组中
                    arry.push($(this).val());
                });
                //将数组元素连接起来转化为字符串
                var arrystr = arry.join(',');
                //输出到控制台
                console.log("选中值:" + arrystr);
            
        }
        var CodeCheck2 = function () {
            //通过id获取多选框是否选中
            var addcode= $('#a').is(":checked");
            var deletecode= $('#b').is(":checked");
            var updatecode= $('#c').is(":checked");
            var selectcode= $('#d').is(":checked");
            //在控制台输出选中值
            console.log("增:" + addcode);
            console.log("删:" + deletecode);
            console.log("改:" + updatecode);
            console.log("查:" + selectcode);
        }

    实例:

     

  • 相关阅读:
    kotlin中值范围
    kotlin中集合
    kotlin数据解构
    Java 8 Lambda 表达式
    kotlin 之内联函数
    kotlin之函数的范围和泛型函数
    kotlin函数的参数和返回值
    kotlin 之单表达式函数
    kotlin使用中辍标记法调用函数
    kotlin之函数的基本用法
  • 原文地址:https://www.cnblogs.com/mvpbest/p/15761762.html
Copyright © 2020-2023  润新知