js动态写入check; 设置 checked; 选取,获取数据

js动态写入check; 设置 checked; 选取,获取数据_第1张图片

  
学历:
   研究生
   全日制本科
   大学本科
   大学专科
   专科以下
// 动态写入html var n_partmentids = brushval(partmentids); if (partmentlist) { var names = ""; for (var i in partmentlist) { if (n_partmentids.indexOf(partmentlist[i].partmentid) > -1) { var inpHtml = '' + partmentlist[i].UNITNAME + '
'; $(".partmentHtml").append(inpHtml); var name = partmentlist[i].UNITNAME; names += (name + ","); } else if (partmentlist[i].UNITNAME == undefined) {} else { var inpHtml = '' + partmentlist[i].UNITNAME + '
'; $(".partmentHtml").append(inpHtml); } $('.partmentName').val(names); } } //array去重 function brushval(arr) { var new_arr_ids = []; for (var i = 0; i < arr.length; i++) { var items = arr[i]; if ($.inArray(items, new_arr_ids) == -1) { new_arr_ids.push(items); } } return new_arr_ids; } //设置默认 checked if (educationals[0]) { var edunames = ""; for (i in educationals) { if (typeof educationals[i] == "string") { $('.edu' + educationals[i]).prop("checked", true); var name = $('.edu' + educationals[i]).attr("data") edunames += (name + ","); } } $('.eduName').val(edunames); } //学历: $(".cbInp").focus(function() { if ($('.cbSele').css("display") == "inline-block" || $('.cbSele').css("display") == "block") { $(".cbSele").css("display", "none"); } else { $(".cbSele").css("display", "inline-block"); } }); $(".cbInp").blur(function() {}); $("input[name='cb']").change(function() { var ids = ""; var texts = ""; $("input:checkbox[name='cb']:checked").each(function(i) { var t = $(this).val(); if (t == 1) { tn = '研究生' } else if (t == 2) { tn = '全日制本科' } else if (t == 3) { tn = '大学本科' } else if (t == 4) { tn = '大学专科' } else { tn = '专科以下' } if (0 == i) { ids = tn; texts = $(this).val(); } else { ids += ("," + tn); texts += ("," + $(this).val()); } }); $('.cbInp').val(ids); $('.educational').val(texts); if (ids == '') { var nt = '请选择' $('.cbInp').val(nt); $('.educational').val(''); } }); //删除指定数据 Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; }; // 给数组添加remove 函数,即删除指定元素。 Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } }; // 使用方法 new_arr_texts.remove(checkedtext);

js动态写入check; 设置 checked; 选取,获取数据_第2张图片

    				
单位名称:
全选 全不选
//动态写入html var n_partmentids = brushval(partmentids); if (partmentlist) { var names = ""; for (var i in partmentlist) { if (n_partmentids.indexOf(partmentlist[i].partmentid) > -1) { var inpHtml = '' + partmentlist[i].UNITNAME + '
'; $(".partmentHtml").append(inpHtml); var name = partmentlist[i].UNITNAME; names += (name + ","); } else if (partmentlist[i].UNITNAME == undefined) {} else { var inpHtml = '' + partmentlist[i].UNITNAME + '
'; $(".partmentHtml").append(inpHtml); } $('.partmentName').val(names); } } //单位名称 $(".cbInp4").focus(function() { if ($('.cbSele4').css("display") == "inline-block" || $('.cbSele4').css("display") == "block") { $(".cbSele4").css("display", "none"); } else { $(".cbSele4").css("display", "inline-block"); } }); $(".cbInp").blur(function() {}); $("input[name='cb4']").change(function() { var ids = ""; var texts = ""; var checkedval; var checkedtext; if (!$(this).is(':checked')) { checkedval = $(this).val(); checkedtext = $(this).attr("data"); $(this).prop("checked", false) } $("input:checkbox[name='cb4']:checked").each(function(i, value) { var v = $(this).val(); var t = value.nextSibling.nodeValue; if (0 == i) { ids = v; texts = t; } else { ids += ("," + v); texts += ("," + t); } }); var idsArr = ids.split(","); var textsArr = texts.split(","); var new_arr_ids = brushval(idsArr) var new_arr_texts = brushval(textsArr) new_arr_ids.remove(checkedval); new_arr_texts.remove(checkedtext); $('.partmentid').val(new_arr_ids); $('.partmentName').val(new_arr_texts); if (ids == '') { var nt = '请选择' $('.partmentName').val(nt); $('.partmentid').val(''); } }); //全选 $(".partmentAll").click(function() { $("[name=cb4]:checkbox").each(function() { $(this).prop("checked", true); }); var ids = ""; var texts = ""; $("input:checkbox[name='cb4']:checked").each(function(i, value) { var v = $(this).val(); var t = value.nextSibling.nodeValue; if (0 == i) { ids = v; texts = t } else { ids += ("," + v); texts += ("," + t); } }); $('.partmentid').val(ids); $('.partmentName').val(texts); if (ids == '') { var nt = '请选择' $('.partmentName').val(nt); $('.partmentid').val(''); } }); //全不选 $(".partmentUn").click(function() { $("[name=cb4]:checkbox").each(function() { $(this).prop("checked", false); }); var nt = '请选择' $('.partmentName').val(nt); $('.partmentid').val(''); });

你可能感兴趣的:(传统技能,--,js,javascript,开发语言)