zoukankan      html  css  js  c++  java
  • 常用函数

    new Date($scope.reg.birthday)=="Invalid Date"

    Angular 常用

    ng-repeat,ng-repeat-start,ng-repeat-end,ng-value,ng-init

    <p ng-repeat="itemSec in itemsub.orderOptionItems" ng-if="$index % 2 ==0" >
    <span ng-if="$index+0<itemsub.orderOptionItems.length">&nbsp;&nbsp;{{itemsub.orderOptionItems[$index+0].optionDetail |to_trusted}} </span>
    <span ng-if="$index+1<itemsub.orderOptionItems.length">&nbsp;&nbsp;{{itemsub.orderOptionItems[$index+1].optionDetail |to_trusted}}</span>
    </p>

    .filter('to_trusted', function(){
    return function(value) {
    var reg=new RegExp("<[^>]+>","g");
    if(!!value){
    return value.replace(reg,"");
    }else{
    return "";
    }

    }
    })

    .filter('abs', function () {
    return function(val) {
    return Math.abs(val);
    }
    })

    {{items.balance | abs | number:2 }}
    {{ aa |to_trusted}}

    return function(a, params) {

    if (params) {
    return $filter('filter')(a, params);
    } else {
    return [];
    }
    }
    <li ng-repeat='name in names | nonBlankFilter:q'> {{name}} </li>
    <input ng-model='q' />

    去重Array还有更简单

    function unique5(array){
      var r = [];
      for(var i = 0, l = array.length; i < l; i++) {
        for(var j = i + 1; j < l; j++)
          if (array[i] === array[j]) j = ++i;
        r.push(array[i]);
      }
      return r;
    }
    Array.prototype.unique3 = function () {
        // 构建一个新数组存放结果
        var newArray = [];
        // 创建一个空对象
        var object = {};
        // for循环时,每次取出一个元素与对象进行对比
        // 如果这个元素不重复,则将它存放到结果数中
        // 同时把这个元素的内容作为对象的一个属性,并赋值为1,
        // 存入到第2步建立的对象中
        for (var i = 0; i < this.length; i++){
            // 检测在object对象中是否包含遍历到的元素的值
            if(!object[typeof(this[i]) + this[i]]) {
                // 如果不包含,将存入对象的元素的值推入到结果数组中
                newArray.push(this[i]);
                // 如果不包含,存入object对象中该属性名的值设置为1
                object[typeof(this[i]) + this[i]] = 1;
            }
        }
        return newArray;
    }
    

    但在ES6去重还有更简单,更优化的方案,比如:

    // ES6
    function unique (arr) {
        const seen = new Map()
        return arr.filter((a) => !seen.has(a) && seen.set(a, 1))
    }
    // or
    function unique (arr) {
        return Array.from(new Set(arr))
    }

    auto-font-size:

    document.querySelector("#fitin span").style.fontSize="56px";
    /*alert(document.querySelector("#fitin span").offsetHeight);
    alert(document.querySelector("#fitin").offsetHeight); */
    setTimeout(function(){
    while( document.querySelector("#fitin span").offsetHeight >document.querySelector("#fitin").offsetHeight ) {
    document.querySelector("#fitin span").style.fontSize=(parseInt(document.querySelector("#fitin span").style.fontSize)-1)+"px"
    }
    }, 0);

    $(function() {
    $('#fitin div').css('font-size', '5em');
    while( $('#fitin div').height() > $('#fitin').height() ) {
    $('#fitin div').css('font-size', (parseInt($('#fitin div').css('font-size')) - 1) + "px" );
    $('div').css('font-size', (parseInt($('#fitin div').css('font-size')) - 1) + "px" );
    }

    });

    function isArray(e){
    var sign=false;
    if(!!a && a instanceof Array && a.length){
    sign=true;
    }
    return sign;
    }
    function isObject(e){
    var sign=false;
    if(!!a && a instanceof Object && !(a instanceof Array) && Object.keys(a).length){
    sign=true;
    }
    return sign;
    }

    a.sort();a.reverse(); var tempList=[{"a":"sx","order":"2"},{"a":"sx","order":"34"}];

    tempList.sort(function(a, b) {//顺序与倒离
    return a.order - b.order;
    });

    function stopBubble(event) { //停止冒泡
    var e = event || window.event;
    if (e && e.stopPropagation )
    e.stopPropagation();
    else
    window.event.cancelBubble = true;
    }

    function stopDefault(event) { //停止默认事件
    var e = event || window.event;
    if(e && e.preventDefault) {
     e.preventDefault();
    } else {
    window.event.returnValue = false;
    }
    return false;
    }

    function mytoFixed(object,num){
    if(!!parseFloat(object)){
    var tempnum = parseFloat(object).toFixed(num+4);
    return Number(Math.round(tempnum+'e'+num)+'e-'+num);
    }else{
    return 0;
    }
    };

    function toFixed(num, s) {
    var times = Math.pow(10, s)
    if(!!parseFloat(num)){
    var des = num * times + 0.5
    des = parseInt(des, 10) / times
    return des
    }else{
    return 0;
    }
    }

    var determineOrder=function(a,b){ //比较大小,-1,0,1
    var result=a.localeCompare(b);
    if(result<0){
    return -1;
    }else if(result>0){
    return 1
    }else{
    return 0;
    }
    }

    window.onload = function() {
    var el = document.getElementById("Test");
    if(window.addEventListener){
    el.addEventListener("click", handleMessage, false);
    }
    else{
    el.attachEvent("onclick", handleMessage);
    }

    function handleMessage(event) {
    event = event || window.event;
     console.log(event.target.getAttribute("aa"));
    }
    }

    var EventUtil = { 

        addHandler: function (element, type, handler) { 

          if(element.addEventListener) { 

            element.addEventListener(type, handler, false); 

          }else if (element.attachEvent) {

            element.attachEvent("on" + type, handler); 

          }else { 

            element["on" + type] = handler;

          } 

        }

       }; 

    if(!!window.navigator.onLine) {alert("首次 -- 已连接");}
    else { alert("首次 -- 未连接"); }

    EventUtil.addHandler(window, "online", function () { alert("Online"); }); 

    EventUtil.addHandler(window, "offline", function () { alert("Offline"); });

    function getCurrentStyle(ele,attr){


    if(document.defaultView){
    var style = document.defaultView.getComputedStyle(ele,null);
    return style ? style.getPropertyValue(attr): null;
    }else{
    return ele.currentStyle[attr];
    }
    }

    var test = document.getElementById('test');

    var style = getCurrentStyle(test,"background-color");

    alert(style);

    function setStyle(obj,css,sign){ //false 累加,true一次性加
    var appendStr="";
    for(var atr in css){
    if(!!sign){appendStr+=atr+":"+css[atr];}
    obj.style[atr] = css[atr];

    }
    if(!!sign) obj.style.cssText=appendStr;
    }
    var head= document.getElementById("head");
    setStyle(head,{"200px",height:"70px",display:"block"},false);

    console.log(getKeyValue("http://www.baiu.com?s1=3&n=s"))

    function getKeyValue(url) {
    var result = {};
    var reg = new RegExp('([\?|&])(.+?)=([^&?]*)', 'ig');
    var arr = reg.exec(url);

    while (arr) {
    result[arr[2]] = arr[3];

    arr = reg.exec(url);
    }

    return result;
    }

    <meta http-equiv="refresh" content="5;url=http://www.helloweba.com">
    function goWeb(){
    var aa = document.createElement("a");
    aa.setAttribute("href","http://www.helloweba.com");
    var bodys=document.getElementsByTagName("body")[0];
    bodys.appendChild(aa);
    aa.click();
    //window.location.href="http://www.helloweba.com";
    }

     url解:

    var ip=$location.host();
    var port=$location.port();
    var url=$location.search();
    var clientPort=url.port;

    =============CSS========= CSS  http://www.css3maker.com/border-radius.html http://www.htmllion.com/css-border-radius-tool.html

    display: flex;
    align-items: center; /*定义body的元素垂直居中*/ vertical-align:middle
    justify-content: center; /*定义body的里的元素水平居中*/ text-align:center

     box-sizing: border-box;

  • 相关阅读:
    -bash: fork: Cannot allocate memory 问题的处理
    Docker top 命令
    docker常见问题修复方法
    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    What's the difference between encoding and charset?
    hexcode of é î Latin-1 Supplement
    炉石Advanced rulebook
    炉石bug反馈
    Sidecar pattern
    SQL JOIN
  • 原文地址:https://www.cnblogs.com/jayruan/p/5246661.html
Copyright © 2011-2022 走看看