js开发编程,基础实现
<script> //--------------详情 //--取值 //下选月份的值 var value = $('#ddlMonth option:selected').val(); var selectTime = selectTime.replace("-", ""); var thisMonth = $(this).children(".selectMonth");//子级的css var strval = value.toFixed(3).toString(); //保留3位小数 //--转换 var jsonData = d.treeList; //获取json对象 var strData = JSON.stringify(jsonData); //将json对象:转为字符串 var jsonData = JSON.parse(strData) //将字符串:转为json对象 var arrValue = strData.split(","); //将字符串,转为array对象 //--input按钮 $("#btnSave").attr({ "disabled": "disabled" });//禁用 $("#btnSave").val("更新中"); // $("#btnSave").removeAttr("disabled"); //启用 $("#btnSave").val("更新当月"); //--div样式 $(".divList ul li:last").css("border-right", "none"); $(".divList").css("width", "100%"); //父级找到class去掉样式 $(this).parent().siblings().find(".area").removeClass("bgff5500"); 第2个li隐藏 var lis = $(".divtype li"); lis[2].style.display = "none"; //最后一个li隐藏边框 $(function () { $(".divtype ul li:last").css("border-right", "none"); }); $(".divtype").css("width", "100%"); $alert("数据不足正在收集中...", 'warning');//success,warning,info,danger //--------------编辑 //下选选中 var iType = '@ViewBag.Type'; $("#ddlType [value=" + iType +"]").attr("selected", true); //默认选中简 $("#ddlType").find("option[value=" + iType + "]").prop("selected", true); //默认选中 $("#ddlType option:contains('" + d.data.Unit+"')").attr("selected", true); //默认选中 //--------------循环 //多选项[去选] $("#typeSize option").each(function () { $(this).removeAttr("selected"); //***所有选中项清除 }); //多选项对象 var typeSize = document.getElementById("typeSize"); //多选项循环每一项[选中] for (var i = 0; i < typeSize.options.length; i++) { if (typeSize.options[i].value == tabvalue) { typeSize.options[i].selected = true;//***对应的项选中 break; } } //多选项,默认选中Box var listBox = $("input[name='cbBox']"); for (var i = 0; i < listBox.length; i++) { var varSelect = $("#hfCheckIds").val(); var arrSelect = varSelect.split(","); for (var j = 0; j < arrSelect.length; j++) { if (listBox[i].value == arrSelect[j]) { listBox[i].checked = true; } } } //--------------选择 //选择事件 $("#ddlSelect").change(function () { var selectTime = $('#ddlSelect option:selected').val(); selectTime = selectTime.replace("-", ""); }); //多选 //<opt:comselect onchange="SetNames(this);" class="form-control" multiple="multiple" x-for="Ids"></opt:comselect> //<input type="hidden" asp-for="hdNames" /> function SetNames(list) { var names = []; for (var i = 0; i < list.options.length; i++) { var option = list.options[i]; if (option.selected) names.push(option.text); } $('#hdNames').val(names); } //--------------点击 //此div加上class,其余去除class $(".stepmain .steplist .stepopen").click(function () { $(this).addClass("off").siblings().removeClass("off"); }); //此div加上class,其余去除class $(".stepmain .steplist .stepclose").click(function () { $(this).addClass("off").siblings().removeClass("off"); $(this).parent().find(".stepmemo").addClass("off"); }); $(function () { $('.divMain').on("click", 'div input', function () { debugger; var thisobj = $(this); var thisval = thisobj.val(); if (thisval != "") { var moreIds = $("#hfIds"); var thisIds = thisval + ","; // if (thisobj.is(":checked")) { moreIds.val(moreIds.val() + thisIds); } else { moreIds.val(moreIds.val().replace(thisIds, "")); } } }); $("a").attr("target", "_top"); $("form").attr("target", "_top"); }); //加减数量 function Setnum(type) { switch (type) { case "reduce"://减 var num = parseFloat($("#txtnum").val()); if (!isNaN(num)) { $("#txtnum").val(num - 1); } break; case "add"://加 var num = parseInt($("#txtnum").val()); if (!isNaN(num)) { $("#txtnum").val(num + 1); } break; } } //全选 function CheckAll() { $(".divListEtp").find("input[type='checkbox']").prop("checked", true); $("#hfCheckIds").val($("#allTypeId").val()); } //去选 function CheckNo() { $(".divListEtp").find("input[type='checkbox']").removeAttr("checked"); $("#hfCheckIds").val(""); } //点击checkbox var html += "<input type=\"checkbox\" name=\"cbBox\" value='" + dataJson[i].value + "' onclick='GetCheckBox(this)' />"; //点击checkbox时为隐藏input追加id值 function GetCheckBox(inputBox) { var result = ""; var arrBoxSelect = $("#hfCheckIds").val(); //隐藏已经选中的ids值 var thisBoxValue = $(inputBox).val() + ",";//要追加的当前checkbox的值 if ($(inputBox).is(':checked')) { result = arrBoxSelect + thisBoxValue; } else { result = arrBoxSelect.replace(thisBoxValue, ""); } $("#hfCheckIds").val(result); } //--------------Ajax $(function () { $('.dtData').on("click", '.trRow .tdDel', function () { var thisobj = $(this); var tname = thisobj.attr("name"); var tid = thisobj.attr("tid"); if (confirm("你确定要删除'" + tname + "'当前信息吗")) { $.ajax({ url: "@Url.ActionUrl("Delete")", data: { id: tid }, dataType: 'JSON', type: 'POST', success: function (d) { $(".fade").hide(); $(".fade").removeClass("In"); thisobj.jsModal('@Url.ActionUrl("Detail")?id=' + tid + ''); //location.href = location.href; } }); } }); // $(".times .btn-item").click(function () { var thisLi = $(this); var thisName = $(this).children(".selectName"); var bool = $(this).hasClass("btn-item") if (bool == true) { var month = $(this).attr("month"); GetSave(month, thisLi, thisName); } }); function GetSave(month, thisLi, thisName) { $.ajax({ url: "@Url.Action("SaveJson", "Type")", data: { month: month }, dataType: 'JSON', type: 'POST', success: function (d) { if (d.result == 1) { $(".divMonth").html(d.month); } $(".times li").each(function () { $(this).addClass("btn-item"); $(this).css("cursor", "pointer"); }); $(thisName).html("月份"); } }); } }); </script>