您的位置:首页 > Web前端 > JQuery

jQuery 屏蔽页面再次被按和延迟加载函数

2013-03-13 10:06 363 查看
jQuery 屏蔽页面再次被按JS文件template_opt.js,内容如下

var common = {

//随机字符

randStr:function(length){

var chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ23456789";

var str = "";

var charLen = chars.length;

while(str.length<length){

var randNum = Math.floor(Math.random()*charLen+1);

str += chars.substr(randNum,1);

}

return str;

},



//更换验证码

changeVerify:function(verifyImgID,verifyImgUrl){

$('#'+verifyImgID).attr('src',verifyImgUrl+'?code='+Math.random());

return false;

},



rescript:function(value){

return value.replace(/[^\w\d]/g,'');

},



//定时跳转

gotoUrl:function(url,time){

if(time < 1){

window.location.href = url;

return;

}

setTimeout("common.gotoUrl("+"'"+url+"'"+",0)",time*1000);

},



addMask:function(color,alpha,width,height){

if(!color)

color = '#000';

if(isNaN(alpha))

alpha = 0.5;

if(isNaN(width))

width = $(document).width();

if(isNaN(height))

height = $(document).height();

var styles = 'width:'+width+'px; height:'+height+'px; filter: Alpha(opacity='+(alpha*100)+');opacity:'+alpha+'; background:'+color+'; position:absolute; z-index:100';

var mask = '<div id="commonMask" style="'+styles+'" oncontextmenu="return (false)" onselectstart="return (false)" onpaste="return (false)" oncopy="return (false)" oncut="return (false)"></div>';

$('body').prepend(mask);

return $("#commonMask");

},



removeMask:function(){

var maskObj = $("#commonMask");

if(maskObj)

maskObj.remove();

},



loadCssFile:function(cssFile){

var cssLink = '<link href="'+cssFile+'" rel="stylesheet" type="text/css" />';

$('head').prepend(cssLink);

},



removeCssFile:function(cssFile){

$('link').each(function(){

if(this.href == cssFile){

$(this).remove();

return false;

}

});

}

}

var target=[];

var time_id=[];

function show_date_time_0(){

setTimeout("show_date_time_0()", 1000);

for (var i=0,j=target.length;i<j;i++){

today=new Date();

timeold=target[i]-today.getTime();

sectimeold=timeold/1000;

secondsold=Math.floor(sectimeold);

msPerDay=24*60*60*1000;

e_daysold=timeold/msPerDay;

daysold=Math.floor(e_daysold);

e_hrsold=(e_daysold-daysold)*24;

hrsold=Math.floor(e_hrsold);

e_minsold=(e_hrsold-hrsold)*60;

minsold=Math.floor((e_hrsold-hrsold)*60);

seconds=Math.floor((e_minsold-minsold)*60);

if (daysold<0) {

document.getElementById(time_id[i]).innerHTML="逾期,倒计时已经失效";

}

else {

if (daysold<10) {daysold="0"+daysold}

// if (daysold<100) {daysold="0"+daysold}

if (hrsold<10) {hrsold="0"+hrsold}

if (minsold<10) {minsold="0"+minsold}

if (seconds<10) {seconds="0"+seconds}

if (daysold<3) {

document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒</font>";

}

else {

document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";

}

}

}

}

setTimeout("show_date_time_0()", 100);

// utility function to retrieve an expiration data in proper format;

function getExpDate(days, hours, minutes)

{

var expDate = new Date();

if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number")

{

expDate.setDate(expDate.getDate() + parseInt(days));

expDate.setHours(expDate.getHours() + parseInt(hours));

expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));

return expDate.toGMTString();

}

}

//utility function called by getCookie()

function getCookieVal(offset)

{

var endstr = document.cookie.indexOf(";", offset);

if(endstr == -1)

{

endstr = document.cookie.length;

}

return unescape(document.cookie.substring(offset, endstr));

}

// primary function to retrieve cookie by name

function getCookie(name)

{

var arg = name + "=";

var alen = arg.length;

var clen = document.cookie.length;

var i = 0;

while(i < clen)

{

var j = i + alen;

if (document.cookie.substring(i, j) == arg)

{

return getCookieVal(j);

}

i = document.cookie.indexOf(" ", i) + 1;

if(i == 0) break;

}

return;

}

// store cookie value with optional details as needed

function setCookie(name, value, expires, path, domain, secure)

{

document.cookie = name + "=" + escape(value) +

((expires) ? "; expires=" + expires : "") +

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

((secure) ? "; secure" : "");

}

// remove the cookie by setting ancient expiration date

function deleteCookie(name,path,domain)

{

if(getCookie(name))

{

document.cookie = name + "=" +

((path) ? "; path=" + path : "") +

((domain) ? "; domain=" + domain : "") +

"; expires=Thu, 01-Jan-70 00:00:01 GMT";

}

}

1、调用方法:

//添加屏蔽功能

function addMask_load(){

common.addMask("#000",0.5);

//var strPath = window.document.location.pathname;

//var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);

//alert(strPath);



var html = '<div id="load1234" style="width: 585px;height: 401px; top: 280px; left: 350px;position: absolute;z-index:1234;background: url(../images/alertBg.png) no-repeat;">';

html += '<div style=" position: absolute;">';

html += '<img src="../images/alertNtitle.jpg" width="585" height="55" border="0" />';

html += '</div>';

html += '<div style="position: absolute;width: 583px;height: 53px; font-size: 24px; font-weight: 600; line-height:50px;color: white;">';

html += ' 提示信息';

html += '</div>';

html += '<div style="position: absolute;width: 583px;height: 345px;margin-top: 54px;font-size: 24px; ">';

html += '<div style="margin-top: 60px;text-align:center;">';

html += '正在查询,请稍候...';

html += '</div>';

html += '</div>';

html += '</div>';



//alert(html);



$('body').prepend(html);



}

//取消屏蔽功能

function removeMask_can(){

common.removeMask();

var load1234Obj = $("#load1234");

if(load1234Obj)load1234Obj.remove();

}

2.延迟加载函数

//延时执行跳转或执行函数

//url可以为地址或者定义好的javascript/jquery函数,

//定义每次延时时间和延时次数,

//callback是每次延时可以执行的回调函数

//

//调用示例

//jump(function(){login(email, password);},3,500,function(){

// $('#register_panel .login_text .success').html($('#register_panel .login_text .success').html()+'.');

//});

function jump(url,times,count,callback) {

var type = typeof(url);

if(times) {

window.setTimeout(function(){

times--;

callback();

if(times > 0) jump(url,times,count,callback);

else {

type == 'function' ? url() : location.href = url;

}

}, count);

} else type == 'function' ? url() : location.href = url;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: