Fork me on GitHub

常用js

//除法
function dataDivisition(a, b) {
            if (b != "0") {
                return (a / b * 100).toFixed(2) + "%";
            }

            return "0%";
}

//查找集合某个对象是否存在,不存在就新增

function arrDeal(arrList) {
  var allTypeArr = ["空调类", "电梯类", "木工类", "五金类", "水电类", "消防类", "其他"];
  for (var i = 0; i < allTypeArr.length; i++) {
    var result = arrList.some(item => {
    if (item.name == allTypeArr[i]) {
      return true;
    }
  })

  if (!result) {
    arrList.push({ value: 0, name: allTypeArr[i] });
  }
  }

  return arrList;
}

 

//input验证只能输入数字,并进行计算

<asp:TextBox ID="txtWaterFees" oninput = "value=value.replace(/^\D*(\d*(?:\.\d{0,4})?).*$/g,'$1'),calculateAmount()" Width="500px" CssClass="input" runat="server"></asp:TextBox>

function calculateAmount() {
  var txtWaterFees = $("#txtWaterFees").val();
  var txtElecricityFees = $("#txtElecricityFees").val();
  if (txtWaterFees != "" && txtElecricityFees != "") {
    $("#txtSumFees").val(parseFloat(txtWaterFees) + parseFloat(txtElecricityFees));
  } else {
    $("#txtSumFees").val('');
  }
}

  

posted @ 2022-09-14 15:25  WantRemake  阅读(23)  评论(0编辑  收藏  举报