zoukankan      html  css  js  c++  java
  • 关于javascript,多种函数封装!!

    1.获取最终的属性

    function getStyleAttr(obj, attr){
    if(window.getComputedStyle){
    return window.getComputedStyle(obj)[attr];
    }else{
    return obj.currentStyle[attr];
    }
    }
     
    2.data
    //当月有多少天
    function getMonthDays(date) { //获取要知道的 年,月份。
    var temp = new Date();//获取一个时间对象。 2018.09.29
    temp.setFullYear(date.getFullYear());//获取年份 2018
    temp.setDate(1);//让月分从 第一天开始。
    temp.setMonth(date.getMonth() + 1); //将月份加1 返还下个月分。
    temp.setDate(0); //再将天数设0,又自动转换为当月的最后一天。
    return temp.getDate();//返还天数
    }

    //获取当月一号 是星期几。
    function getFirstDayWeek(date) {//获取要知道的 年,月份。
    var temp = new Date("2018-01-01");//获取一个时间对象。
    temp.setFullYear(date.getFullYear());//获取年份。
    temp.setMonth(date.getMonth());//获取月份
    return temp.getDay();//根据天数对象 自动转换为 星期几。
    }

    //获取上个月 有多少天。
    function getPrevMonthDays (date) {//获取要知道的 年,月份。
    var temp = new Date("2018-01-01");//获取一个时间对象。
    temp.setFullYear(date.getFullYear());//获取年份
    temp.setMonth(date.getMonth()); //获取 月份
    temp.setDate(0); //将天数设0,自动转换为当 上一个月的最后一天。
    return temp.getDate(); //返还天数
    }
     
    //将时间格式化 yyyy-mm-dd yyyy年mm月dd天
    function (str) {
    var year = this.getFullYear();
    var month = this.getMonth() + 1;
    var day = this.getDate();
    return str
    .replace("yyyy", year)
    .replace("mm", month)
    .replace("dd", day);
    };
  • 相关阅读:
    JavaScript常用函数和方法
    Django中csrf错误
    LVS+Keepalived负载均衡配置
    CSP-S2019 游记
    三角函数公式整理
    LGOJP3193 [HNOI2008]GT考试
    BZOJ3790. 神奇项链
    BZOJ4241: 历史研究
    LGOJP2051 [AHOI2009]中国象棋
    AT2000 Leftmost Ball
  • 原文地址:https://www.cnblogs.com/lishixiang-007/p/11381413.html
Copyright © 2011-2022 走看看