`
jiangyaning8
  • 浏览: 17869 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
右键 Flex中的鼠标右键
<script>
function onNsRightClick(e){
    if(e.which == 3){
         FlexTest.openRightClick();
         e.stopPropagation(); 
    }
    stopDefault();
ie i 用div模拟alert对话框,N秒不点击自动关闭(适用IE6、IE7、firefox)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>用div模拟alert对话框</title>
<!-- 为了增加适用性,所有的css样式都写在程序中,调用时只需将selfAlert类引入即可 -->
</head>
<body>
    <br><br><center><h3 style="color:blue">用div模拟alert对话框,一段时间不点击,将自动关闭</h3></center>
</body>

<script type="text/javascript">
    var s = new selfAlert("3秒钟不点击将自动关闭",3000);

/**
 * Descrioption: 模拟alert对话框,一定时间内不点击则自动关闭
 * param    msgstr: 模拟对话框要显示的字符串
 *          timer: 自动关闭时间
 * ps: 适用于 IE6 IE7 firefox
 */
function selfAlert(msgstr,timer){
    //该值可以作为返回值,初始化时为 0 ,点击确定后变为 1 ,点击关闭后变为 2 ,自动关闭 3 
    var alertValue = 0; 

    //确定遮罩层的高度,宽度
    var h = screen.availHeight;
    var w = screen.availWidth;
    //创建遮罩层,它的主要作用就是使网页中的其他元素不可用。
    var dv = document.createElement("div");
    dv.setAttribute('id','bg');
    //设置样式
    dv.style.height = h + "px";
    dv.style.width = w + "px";
    dv.style.zIndex = "1111";
    dv.style.top = 0;
    dv.style.left = 0;
    
    //如果不想遮罩,可以去掉这两句
    dv.style.background = "#fff";
    dv.style.filter = "alpha(opacity=0)";

    //设为绝对定位很重要
    dv.style.position = "absolute";
    //将该元素添加至body中
    document.body.appendChild(dv);

    //创建提示对话框面板
    var dvMsg = document.createElement("div");
    dvMsg.style.position = "absolute";
    dvMsg.setAttribute('id','msg');
    dvMsg.style.width = "280px";
    dvMsg.style.height = "100px";
    dvMsg.style.top="30%";
    dvMsg.style.left="40%";
    dvMsg.style.background = "white";
    dvMsg.style.zIndex = "1112";
    
    //可以继续采用如上形式创建模拟对话框表格,这里为了方便采用html形式
    strHtml =  "<table width='280' height='25' border='0' cellspacing='0' cellpadding='0' align='center'>"
    strHtml += "    <tr height='25' style='line-height:25px;'>"
    strHtml += "        <td width='250' title='移动' style='cursor:move;background:#CFD7EC url(title_bg_left.gif) no-repeat top left;' onmousedown='oMove(parentNode.parentNode.parentNode.parentNode);'>"
    strHtml += "            <font style='font-size:12px;font-weight:bold;color:#000;margin-left:10px;'>消息提示框</font></td>"
    strHtml += "        <td width='30' style='background:#CFD7EC url(title_bg_right.gif) no-repeat right top;'>"
    strHtml += "            <img src='close.gif' style='margin-right:3px;cursor:hand;' onclick='imgClose();'><td></tr>"
    strHtml +=  "</table>"
    strHtml +=  "<table width='280' height='145' border='0' cellspacing='0' cellpadding='0' align='center' style='border:1px solid #343434'>"
    strHtml += "    <tr height='113' bgcolor='#F4F4F4'><td width='' style='padding-left:10;'><img src='info.gif'></td>"
    strHtml += "        <td width='200' align='left'>" + msgstr + "</td></tr>"
    strHtml += "    <tr height='27'><td colspan='2' style='background:#F4F4F4;padding-top:0px;' valign='top' align='center'>"
    strHtml += "         <input type='button' value='确&nbsp;定' style='width:70;' onclick='btnclick()'></td></tr>"
    strHtml += "</table>"
    dvMsg.innerHTML = strHtml;
    document.body.appendChild(dvMsg);

    //点击关闭按钮
    imgClose = function (){
        alertValue = 2; // 2 代表点击了关闭按钮
        document.body.removeChild(dv);
        document.body.removeChild(dvMsg);
    }
    //点击确定按钮
    btnclick = function (){
        alertValue = 1; // 1 代表点击了确定按钮
        document.body.removeChild(dv);
        document.body.removeChild(dvMsg);
    }
    
    remove = function ()
    {
        //timer时间过后如果仍未点击,则自动关闭selfAlert框
        if(alertValue==0){
            document.body.removeChild(dv);
            document.body.removeChild(dvMsg);
        }
    }
    //timer秒后自动关闭selfAlert(提示框)
    setTimeout("remove()",timer);
    
    //实现鼠标拖动对话框
    oMove = function(obj) {
        var otop,oleft;
        otop = event.y - obj.offsetTop;
        oleft = event.x - obj.offsetLeft;
        obj.setCapture();

        obj.onmousemove  = function()
        {
            obj.style.left = event.x - oleft;
            obj.style.top = event.y - otop;
        }
        obj.onmouseup  = function()
        {
            obj.onmousemove = null;
            obj.style.filter = null;
            obj.releaseCapture();
        }
    }
}
</script>
</html>
ie 用div模拟alert对话框,N秒不点击自动关闭(适用IE6、IE7、firefox)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<input type="button" value="弹出alert框,一秒后自动关闭;" onClick="JavaScript:myAlert('不点击确定三秒后自动跳转')">
</body>

<script type="text/javascript">
    /**
     *@Description:弹出一个alert对话框,三秒钟内不点击确定,自动关闭alert框,该框最终模拟成非模态形式
     *              经验证,适用于 IE6,不兼容IE7,firefox
     *@param:  showstr     alert框里要显示的文本
    */
    function myAlert(showstr)
    {
        var alertInfo = showstr;  //传递alert框里要显示的信息
        var timer = 3000;   //设定停留的时间为3000ms,即3秒
        //在页面中新建一个框架frame,以便在该frame中弹出一个非模态对话框
        document.body.innerHTML += "<iframe style='display:none;' width='500' name='ifrtemp'></iframe>";
        //在非模态对话框中弹出一个alert框,并立即关闭该非模态对话框
        ifrtemp.showModelessDialog("javascript:alert('"+alertInfo+"');window.close();",
                "",
                "status:no;resizable:no;help:no;dialogHeight:530px;dialogWidth:40px;");
        setTimeout("ifrtemp.location.reload();",timer); //停留一段时间后强行关闭alert窗口
    }
</script>
</html>
Global site tag (gtag.js) - Google Analytics