一、获取查询字符串字段
function query_url(name){
var query = location.search.substring(1),
arry = [],
len,
i,
single_query = [],
property,
obj = {};
arry = query.split("&");
len = arry.length;
for(i = 0; i < len; i++){
single_query = arry[i].split("=");
property = single_query[0];
obj[property] = single_query[1];
}
return obj[name];
}
var name = url_query(name);
二、SMS验证码倒计时效果-------点第一次开始倒计时;倒计时未完成点击无效;倒计时完成点击出新的倒计时
var timer,
_time = Boolean(timer);
if(_time){
return true;
}else{
if(sms.disabled){
sms.removeAttribute("disabled");
}
var time_num = 60;
sms_btn.innerText ="(" + time_num + ")秒再次获取";
timer = setInterval(function(){
time_num--;
sms_btn.innerText ="(" + time_num + ")秒再次获取";
if(time_num == 1){
sms_btn.innerText ="重新获取验证码";
clearInterval(timer);
timer = false;
}
},1000);
}
三、获取带汉字的字符串的长度
function cc_len(str){
var len=0,
str_len = str.length,
i,
charcode;
for(i = 0; i<str_len; i++){
charcode = str.charCodeAt(i);
if(charcode>=0 && charcode<=128){
len++;
}else{
len+=2;
}
}
return len;
}
四、去除DOM的指定类名函数
function drop_class(dom,str){
var arr = [],
class_str,
new_class="",
len,
i;
class_str = dom.className;
arr = class_str.split(" ");
len = arr.length;
for(i=0; i<len; i++){
if(arr[i] !== str){
new_class +=(" "+arr[i]);
}
}
dom.className = new_class.substr(1);
}
五、【兼容函数】取消浏览器默认行为
function stopDefault( e ) {
if (e&&e.preventDefault ){
e.preventDefault();
}else{
window.event.returnValue = false;
}
return false;
}