常用js函数开始收集~

时间:2022-12-20 06:17:03

获取样式

var getStyle=function(ele,atr){

return typeof(ele)=='undefined'?0: ele.currentStyle? ele.currentStyle[atr] : window.getComputedStyle(ele, null)[atr];

}

时分秒倒计时://使用方法countDown(times,cb),times时间戳,cb,每秒执行的回调,输出,时分秒剩余

function countDown(times,cb) {
var timer = null;
times=times/1000;
timer = setInterval(function() {
var day = 0,
hour = 0,
minute = 0,
second = 0; //时间默认值
if (times > 0) {
// day = Math.floor(times / (60 * 60 * 24));
hour = Math.floor(times / (60 * 60));
minute = Math.floor(times / 60%60);
second = Math.floor(times)%60;
}

// if (hour <= 9) hour = '0' + hour;
if (minute <= 9) minute = '0' + minute;
if (second <= 9) second = '0' + second;
//><span class="paizi"><%=list.diffdays%></span><span class="maohao">天</span>
cb&&cb(hour,minute,second)
// console.log(day + "天:" + hour + "小时:" + minute + "分钟:" + second + "秒");
times--;
}, 1000);
if (times <= 0) {
clearInterval(timer);

}
}

微信内打开QQ聊天:

<a id='sendqq'></a>

document.getElementById('sendqq').setAttribute('href', ' http://wpa.qq.com/msgrd?v=3&uin='+qq+'&site=qq&menu=yes"');//微信内也能打开

其它移动端浏览器中打开QQ聊天:

<a id='sendqq'></a>

document.getElementById('sendqq').setAttribute('href', 'mqqwpa://im/chat?chat_type=wpa&uin=' + qq +
'&version=1&src_type=web')

//移动端浏览器打开

PC端打开QQ聊天:

<a data-v-562a4e36="" href="tencent://message/?uin=*******&amp;Site=Sambow&amp;Menu=yes"></a>//您的QQ号替换星号

微信浏览器判断方法:

var ua = navigator.userAgent.toLowerCase();
var isWeixin = ua.indexOf('micromessenger') != -1;
if(isWeixin){
///是微信内
}else{
//其他浏览器
}
 
 
URL参数获取://使用方式------假如获取www.baidu.com?id=520&page=20,如果要获取id和page,可以用getUrlParms().id; getUrlParms().page;
function getUrlParms(url){
  //首先获取地址
            var url = url || window.location.href;
            //获取传值
            var arr = url.split("?");
            //判断是否有传值
            if (arr.length == 1) {
                return null;
            }
            //获取get传值的个数
            var value_arr = arr[1].split("&");
            //循环生成返回的对象
            var obj = {};
            for (var i = 0; i < value_arr.length; i++) {
                var key_val = value_arr[i].split("=");
                obj[key_val[0]] = key_val[1];
            }
            return obj;
}
url参数格式化://var newobj={id:5,page:10,totalpage:20}得到 ?id=5&page=10&totalpage=20
var parms='';
var index=0;
for(var item in newobj){
index++;
if(index==1){
parms+='?'+item+'='+newobj[item]
}else{
parms+='&'+item+'='+newobj[item]
}
 
}