【Javascript】Javascript常用方法

Javascript常用方法

1、判断一个对象是否为空对象?

	function checkNullObj(obj) {
		return Object.keys(obj).length === 0 && Object.getOwnPropertySymbols(obj).length === 0;
	}

2、返回输入值的数据类型?

	function type(para) {
		return Object.prototype.toString.call(para)
	}

3、返回当前的时间(年月日时分秒)?

	function getDateTime() {
	    var date = new Date(),
	        year = date.getFullYear(),
	        month = date.getMonth() + 1,
	        day = date.getDate(),
	        hour = date.getHours() + 1,
	        minute = date.getMinutes(),
	        second = date.getSeconds();
	    month = checkTime(month);
	    day = checkTime(day);
	    hour = checkTime(hour);
	    minute = checkTime(minute);
	    second = checkTime(second);
	
	    function checkTime(i) {
	        if (i < 10) {
	            i = "0" + i;
	        }
	        return i;
	    }
	    return "" + year + "年" + month + "月" + day + "日" + hour + "时" + minute + "分" + second + "秒"
	}

4、获取url中的参数?

	function getWindonHref() {
	    var sHref = window.location.href;
	    var args = sHref.split('?');
	    if (args[0] === sHref) {
	        return '';
	    }
	    var hrefarr = args[1].split('#')[0].split('&');
	    var obj = {};
	    for (var i = 0; i < hrefarr.length; i++) {
	        hrefarr[i] = hrefarr[i].split('=');
	        obj[hrefarr[i][0]] = hrefarr[i][1];
	    }
	    return obj;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值