• onoffswitch-checkbox


      @foreach (EmailSubscription es in Model)
       {

    if(true){

    <div class="onoffswitch">                     
            <input type="checkbox" checked class="onoffswitch-checkbox" name="onoffswitch_1" id="onoffswitch_1">
            <label class="onoffswitch-label" style="border-radius:23px;" name="onoffswitch_1" for="onoffswitch_1">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch" style="24px;border-radius:12px;"></span>
             </label>
     </div>

    }

    else

    {

            <input type="checkbox"  class="onoffswitch-checkbox" name="onoffswitch_1" id="onoffswitch_1">
            <label class="onoffswitch-label" style="border-radius:23px;" name="onoffswitch_1" for="onoffswitch_1">
                <span class="onoffswitch-inner"></span>
                <span class="onoffswitch-switch" style="24px;border-radius:12px;"></span>
             </label>

    }

    }

    js中对多个onoffswitch-switch 按钮 进行数组形式的赋值

    <script type="text/javascript"> 

    $(document).ready(function(){

           var active= new Array();
            var num= new Array();
            var i = 0;
            $("label[name^='onoffswitch_']").on('click',function (e) {

                var id = $(this).attr("name").split("_")[1];
                var onswitch= document.getElementById("onoffswitch_" + id).checked;
                if (onswitch)
                {
                    active[i] = "false";
                }
                else
                {
                    active[i] = "true";
                }
                num[i] = id;
                i++;
            });

            $("#btnSave").click(function () {

                if (active.length>0 && num.length>0)
                {
                    $(".ajax-loader").show();

                    $.ajax({
                        url: ' ',
                        traditional: true,    //阻止深度序列化,提交时后台处理才能接收到数组值。默认为 false,提交数组必须为true
                        data:
                        {
                            active: active,
                            num: num
                        },
                        complete: function () {
                            $(".ajax-loader").hide();
                        }
                    });
                }
            });

    });

    </script>

    c# 里:control里数组接受和处理,接收数组, 避免未修改时更新数据库

            public ActionResult SaveSubscriptions(string[] active, string[] num)
            {
                bool Isonline = false;
                List<Num> list = _numService.GetNumByCustomerID(logginUser.UserID).ToList();
                if (list.Count>0)
                {
                    for (int i = 0; i < IsOnline.Length; i++)
                    {               
                        var num = new Guid(num[i]);
                        num result = list.Where(a => a.ID == num).FirstOrDefault();
                        if(result.active != Boolean.Parse(active[i]))
                        {
                            if (active[i] == "true")
                            {
                                active = true;
                            }
                            else
                            {
                               active = false;
                            }

                            list.Add(result);
                            active= true;
                        }
                    }
                }
                if (active)
                {
                    _numService.UpdateNum(list);
                }   
               
                return RedirectToAction("Index");
            }

                           

  • 相关阅读:
    UltraIso制作U盘启动盘教程
    Windows7下搭建FTP服务器(使用微软)
    Win7中IIS和ASP的安装、配置和使用
    解决ubuntu中vi不能正常使用方向键与退格键的问题
    SQLSERVER的TOP
    VBA读取文件路径中的文件
    博乐园,我来了
    JSON对象,初步认识
    【原创翻译】深入理解CSS盒子模型
    深入浅出CSS3:backgroundclip,backgroundorigin和borderimage教程
  • 原文地址:https://www.cnblogs.com/yi-miao/p/8058109.html
Copyright © 2020-2023  润新知