文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>简单的JavaScript层覆盖

简单的JavaScript层覆盖

时间:2007-10-06  来源:linxh

本文参考:http://hi.baidu.com/caishaohua8152/blog/item/ef81d41bacd1f8f9ae51335c.html

背景变灰功能实效,并且出现一个“对话框”,内容为调用时指定的代码

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 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 DialogShow(showdata,ow,oh,w,h) {
    var DivWidth=300; //显示区域的宽度

    popCoverDiv();
    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";

        with (signDiv.style) {
            position = 'absolute';
            left = (document.documentElement.clientWidth - DivWidth)/2 +'px';
            top = (document.documentElement.clientHeight - 300)/2 + 'px';
            width = DivWidth + 'px';
            zIndex = 99;
            background = '#FFFFFF';
            border = '#66CCFF solid 1px';
        }
    }
    

    G("sign_div").innerHTML=showdata;
}

function DialogHide() {
    G("sign_div").style.display = 'none';
    G("cover_div").style.display = 'none';
    document.body.style.overflow = '';
}

 

调用:

<input type="button" onclick="var htmlcode='<input type=password>';DialogShow(htmlcode,20,20,20,20);" value="change password"/></p>

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载