zoukankan      html  css  js  c++  java
  • Mutiselect下拉复选框(保存和设置默认选中项)

    HTML代码 
    <asp:DropDownList ID="ddlWarehouseIds" runat="server" CssClass="ddl"></asp:DropDownList> <input type="hidden" name="<%#Eval("WarehouseNames")%>" id="hid_<%#Eval("UserID")%>" value=" <%#Eval("WarehouseIds")%>" />
    
    
    


    Mutiselect 插件地址 http://www.cnblogs.com/xinchuang/archive/2013/05/24/3096757.html

    //设置选中项 ===========================================================

    1
    //初始化 2 $(function() 3 { 4 $(".ddl").multiselect({ 5 noneSelectedText: "--请选择仓库--", 6 checkAllText: "全选", 7 uncheckAllText: '全不选', 8 selectedList:4 9 //header:"7" 10 }); 11 }); 12 //设置默认选中项 13 $(function() 14 { 15 $("#TableList tr td[id]").each(function() 16 { 17 var objs=$(this).children(); 18 var warehouses=objs[2]; 19 var warehouseNames=$(warehouses).attr("name"); 20 var warehouseids=$(warehouses).val(); 21 //展示给用户选择的仓库 22 var spans=$(objs[1]).children(); 23 if(warehouseNames.length>0) 24 { 25 $(spans[1]).text(warehouseNames); 26 } 27 else 28 { 29 $(spans[1]).text("--请选择仓库--"); 30 } 31 //点击文本框 选中默认项 32 var ids=warehouseids.split(","); 33 $(objs[1]).click(function() 34 { 35 var div= $("#UploadForm").nextAll("[name]");//手动改的源码 点击文本框时 给下拉框添加个属性 以标识当前修改的下拉框 36 //alert(div.attr("name")); 37 var ul=$(div).children(":last-child"); 38 // alert (ul.attr("class")); 39 var lis=ul.children(); 40 //alert(lis.length); 41 42 //清空默认选中值 43 $(lis).each(function(){ 44 //获取lable 45 var me=$(this).children(); 46 // alert(me.length); 47 // alert (me.attr("class")); 48 //获取input标签 49 var input=me.children(":first-child"); 50 //删除默认属性 51 input.removeAttr("checked"); 52 input.removeAttr("aria-selected"); 53 }); 54 55 56 for (var j=0;j<ids.length;j++) 57 { 58 for (var i=0;i<lis.length;i++) 59 { 60 //获取lable 61 var me=$(lis[i]).children(); 62 // alert(me.length); 63 // alert (me.attr("class")); 64 //获取input标签 65 var input=me.children(":first-child"); 66 //获取input的值 67 var inputValue=input.val(); 68 69 // alert(inputValue) 70 //删除默认属性 71 //input.removeAttr("checked"); 72 //input.removeAttr("aria-selected"); 73 //重新 绑定数据库中读取的数据 74 if(inputValue*1==ids[j]*1) 75 { 76 $(input).prop("checked","checked"); 77 $(input).attr("aria-selected","true"); 78 } 79 } 80 } 81 }); 82 }) 83 }) 84 //保存========================================= 85 function SaveUserWarehouse(userId,obj) 86 { 87 88 var me =$(obj).parent().prev().children(); 89 var valuestr = me.multiselect("getChecked").map(function () { 90 return this.value; 91 }).get(); 92 //alert(valuestr); 93 // alert(typeof(valuestr)); 94 //var me =$(obj).parent().prev().children(); 95 //var valuestr = me.multiselect("MyValues"); 96 $.ajax({ 97 type: "POST", 98 url: "/B2C/handlers/Warehouse/SaveUserWarehouse.ashx", 99 data: { "warehouseids":valuestr.toString(),"userId":userId}, 100 success: function(msg) 101 { 102 if(msg =="ok") 103 alert ("保存成功!"); 104 reload(); 105 }, 106 error: function() { 107 alert("请求异常,请稍后再试!"); 108 } 109 }); 110 }
  • 相关阅读:
    【JS教程08】数组及操作方法
    【JS教程07】事件属性及匿名函数
    【JS教程06】操作元素
    【JS教程05】获取元素的方法
    【JS教程04】条件语句
    多线程环境下非安全Dictionary引起的“已添加了具有相同键的项”问题
    GPT分区基础知识及如何在GPT分区上安装WIN7
    Jenkins TFS配置
    windows查看端口占用命令
    VS2015企业版序列号
  • 原文地址:https://www.cnblogs.com/q101301/p/4497153.html
Copyright © 2011-2022 走看看