用js背景变灰并且功能失效

     function G(id){
       return document.getElementById(id);
     };
     
    function GC(t){
       return document.createElement(t);
    };
   
    String.prototype.trim = function(){
              return this.replace(/(^/s*)|(/s*$)/g, '');
    };
   
    function isIE(){
          return (document.all && window.ActiveXObject && !window.opera) ? true : false;
    }
   
    function getBodySize(){
           var bodySize = [];
        with(document.documentElement) {
         bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
         bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
        }
           return bodySize;
    }
 
   
  function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
   
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}


只要引用上面的这些JS就可以了,在你弹出DIV或者POPUP的窗口前调用那个popCoverDiv();就可以完成你想要的效果了!


下面是一个很不错的实例:

用javascript实现用户登陆,注册,忘记密码;修改密码等页面功能;

效果弹出用户登陆框而且背景变灰功能实效;好似关闭windows时的页面效果。
例题代码如下(在ie和firefox中均能用):
login.html文件内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript">
function G(id){
    return document.getElementById(id);
};
function GC(t){
   return document.createElement(t);
};
String.prototype.trim = function(){
          return this.replace(/(^/s*)|(/s*$)/g, '');
};
function isIE(){
      return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
     var loginDivWidth = 300;
var sign_in_flow = '<div style="background:#FF9900;">Login</div><div>e-mail:*</div><div>'
       + '<input type="text" id="sign_email" maxlength="64" size="30"/>'
       + '</div><div>password:*</div><div><input type="password" id="sign_pwd" size="30"/>'
        + '</div><div><input type="button" value="login" οnclick="signFlow(1);" id="sign_button"/>   '
        + '   <input type="button" value="cancel" οnclick="cancelSign();"/></div>'
        + '<p><a href="javascript:loadSignUpFlow();">creat account</a>   '
        + 'or   <a href="javascript:loadForgetPwdFlow();">forget password</a></p>';
function loadSignInFlow(){
   G("sign_div").innerHTML = sign_in_flow;
    G("sign_email").focus();
};
var sign_up_flow = '<div style="background:#CCFF00;">Create New Account</div><div>e-mail:*</div><div>'
       + '<input type="text" id="sign_email" maxlength="64" size="30"/>'
       + '</div><div>password:*</div><div><input type="password" id="sign_pwd" size="30"/>'
        + '</div><div>password again:*</div><div><input type="password" id="sign_repwd" size="30"/>'
        + '</div><div><input type="button" value="creat account" οnclick="signFlow(0);" id="sign_button"/> '
        + ' <input type="button" value="cancel" οnclick="cancelSign();"/></div>'
        + '<p><a href="javascript:loadSignInFlow();">login</a></p>';
function loadSignUpFlow(){
   G("sign_div").innerHTML = sign_up_flow;
    G("sign_email").focus();
};
function cancelSign(){
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
   document.body.style.overflow = '';
};
var forget_pwd_flow = '<div style="background:#FF99FF;">Forget Password</div><div>e-mail:*</div><div>'
       + '<input type="text" id="sign_email" maxlength="64" size="30"/>'
        + '</div><div><input type="button" value="sent pwd to e_mail" οnclick="signFlow(2);" id="sign_button"/>   '
        + '   <input type="button" value="cancel" οnclick="cancelSign();"/></div>';
function loadForgetPwdFlow(){
   G("sign_div").innerHTML = forget_pwd_flow;
    G("sign_email").focus();
};
function checkEmail(){
   if((G("sign_email").value.indexOf('@')<=0)||(G("sign_email").value.indexOf('.')<=0)){
    return '<div style="color:#FF0000";">Sorry, unrecognized e_mail.</div>';
   }
   return '';
}
function checkPwd(){
   if(G("sign_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Password field is required.</div>';
   }
   return '';
}
function checkRePwd(){
   if(G("sign_pwd").value.trim() != G("sign_repwd").value.trim()){
    return '<div style="color:#FF0000";">The specified passwords do not match.</div>';
   }
   return '';
}
function signFlow(isSignIn){
    var error = checkEmail();
    var htmlText = null;
    if (isSignIn == 1) {
     if (error == ''){
      error = checkPwd();
     }
     htmlText = sign_in_flow;
    } else if (isSignIn == 0) {
     if (error == ''){
      error = checkPwd();
      if (error == ''){
       error = checkRePwd();
      }
     }
     htmlText = sign_up_flow;
    } else if (isSignIn == 2) {
    htmlText = forget_pwd_flow;
    }
    var eMailValue = G("sign_email").value.trim();
   if (error == '') {
    } else {
    G("sign_div").innerHTML = error + htmlText;
    G("sign_email").value = eMailValue;
    }
};
function popCoverDiv(){
   if (G("cover_div")) {
    G("cover_div").style.display = '';
   } else {
    var coverDiv = GC('div');
    document.body.appendChild(coverDiv);
    coverDiv.id = 'cover_div';
    with(coverDiv.style) {
     position = 'absolute';
     background = '#CCCCCC';
     left = '0px';
     top = '0px';
     var bodySize = getBodySize();
     width = bodySize[0] + 'px'
     height = bodySize[1] + 'px';
     zIndex = 98;
     if (isIE()) {
      filter = "Alpha(Opacity=60)";
     } else {
      opacity = 0.6;
     }
    }
   }
}
function getBodySize(){
   var bodySize = [];
   with(document.documentElement) {
    bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
    bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
   }
   return bodySize;
}

function popSign(isLogin){
   if (G("sign_div")) {
    G("sign_div").style.display = '';
   } else {
    var signDiv = GC('div');
    document.body.appendChild(signDiv);
    signDiv.id = 'sign_div';
    signDiv.align = "center";
    signDiv.onkeypress = function(evt){
          var e = window.event?window.event:evt;
          if (e.keyCode==13 || e.which==13) {
           if (G("sign_button")) {
            G("sign_div").focus();
            G("sign_button").click();
           }
          }
         };
    with (signDiv.style) {
     position = 'absolute';
     left = (document.documentElement.clientWidth - loginDivWidth)/2 + 'px';
     top = (document.documentElement.clientHeight - 300)/2 + 'px';
     width = loginDivWidth + 'px';
     zIndex = 99;
     background = '#FFFFFF';
     border = '#66CCFF solid 1px';
    }
   }
   if(isLogin) {
    G("sign_div").innerHTML = sign_in_flow;
   } else {
    G("sign_div").innerHTML = change_pwd_flow;
   }
  
}
function popSignFlow(isLogin) {
   popCoverDiv();  
   popSign(isLogin);  
   document.body.style.overflow = "hidden";
     
      if(isLogin) {
       G("sign_email").focus();
      } else {
       G("old_pwd").focus();
      }
}
function changePwd(){
    var error = checkOldPwd();
    if (error == ''){
     error = checkPwd();
    }
   if (error == ''){
    error = checkRePwd();
   }

    var oldPwd = G("old_pwd").value.trim();
    var newPwd = G("sign_pwd").value.trim();
   if (error == '') {
     var url = basePath + "?q=tripuser/tripuser_change_pwd_ajax/" + oldPwd + "/" + newPwd;
     exeRequest(url, getSignText, null);
    } else {
    G("sign_div").innerHTML = error + change_pwd_flow;
    }
};
function checkOldPwd(){
   if(G("old_pwd").value.trim() == ''){
    return '<div style="color:#FF0000";">Old Password field is required.</div>';
   }
   return '';
}
var change_pwd_flow = '<div style="background:#33FFFF;">Change Your Password</div><div>old password:*</div><div>'
       + '<input type="password" id="old_pwd" size="30"/>'
       + '</div><div>new password:*</div><div><input type="password" id="sign_pwd" size="30"/>'
        + '</div><div>new password again:*</div><div><input type="password" id="sign_repwd" size="30"/>'
        + '</div><div><input type="button" value="change password" οnclick="changePwd();" id="sign_button"/> '
        + ' <input type="button" value="cancel" οnclick="cancelSign();"/></div>';

</script>
</head><body><div>
<input type="text" value="login"/><p>
<input type="button" οnclick="popSignFlow(1);" value="login"/>   
<input type="button" οnclick="popSignFlow(0);" value="change password"/></p>
</div></body></html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值