一组经典的JS函数

 

下面有几个通用函数.
1.
       /// <param name="Msg">要显示的消息</param>
        /// <returns>alert函数的客户端脚本</returns>
        public static string Client_Alert(string Msg)
        {
            return "<script language="javascript">alert("" + Msg + "");</script>";
        }
2.
          ///<param name="Msg">要显示的消息</param>
        ///<param name="returnURL">返回地址</param>
        ///<returns>返回指定的URL</returns>
        public static string Client_Alert(string Msg, string returnURL)
        {
            return "<script language="javascript">alert("" + Msg + "");location.href='" + returnURL + "';</script>";
        }
3.
               /// <param name="Msg">待确认的消息</param>
        /// <param name="url">确认之后转向的地址</param>
        /// <returns>confirm函数的客户端脚本</returns>
        public static string Client_Confirm(string Msg, string url)
        {
            string scripts = "<script language="javascript">" +
                "if (confirm('" + Msg + "')) " +
                " { location.href='" + url + "'; }" +
                "</script>";
            return scripts;
        }
4.
               /// <param name="Msg">待确认的消息</param>
        /// <param name="cfmurl">确认之后转向的地址</param>
        /// <param name="retrunURL">取消之后转向的地址</param>
        /// <returns>confirm函数的客户端脚本</returns>
        public static string Client_Confirm(string Msg, string cfmurl, string retrunURL)
        {
            string scripts = "<script language="javascript">" +
                "if (confirm('" + Msg + "')) " +
                " { location.href='" + cfmurl + "'; }" +
                "else { location.href='" + retrunURL + "'; }</script>";
            return scripts;
        }
5.
           /// 关闭窗口无提示信息!
      public static string Client_CloseWindow()
        {
            return "<script>window.opener=null;window.close();</script>";
        }

         6.     /// 关闭 窗口前出现提示信息
        /// <param name="MSG">提示关闭信息</param>
        public static string Client_CloseWindow(string MSG)
        {
            return "<script>if(confirm('" + MSG + "')){window.opener=null;window.close();}else{return false;}</script>";
        }

7.   /// <param name="URL">重定向的网址</param>
        /// <param name="CopyHistory">是否记录历史</param>
        /// <returns>重定向网址的客户端脚本块</returns>
        public static string Client_Redirect(string URL, bool CopyHistory)
        {
            return (CopyHistory) ? "<script language="javascript">top.location.href='" + URL + "';</script>" : "<script language="javascript">top.location.replace('" + URL + "');</script>";
        }
8.
     ///<param name="strBody">提示信息内容</param>
        /// <param name="strLocalUrl">转向地址</param>
        /// <returns></returns>
        public static void WriteAlert(string strBody, string strLocalUrl)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="../js/validateForm.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ location.href= '" + strLocalUrl + "';}  function tmRedir(){ window.setTimeout('redir()', 100);} </script> ");
            HttpContext.Current.Response.Write("</head> <body>  <script language="javascript">  function stop(){return false; }  document.οncοntextmenu=stop; </script> <script language=javascript> _error_msg_show('" + strBody + "', 'tmRedir()', '', ''); </script></body></html>");
            HttpContext.Current.Response.End();

        }
9.
        public static void WriteDialogAlert(string strBody, string strLocalUrl)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="../js/validateForm2.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ location.href= '" + strLocalUrl + "';}  function tmRedir(){ window.setTimeout('redir()', 100);} </script> ");
            HttpContext.Current.Response.Write("</head> <body>  <script language="javascript">  function stop(){return false; }  document.οncοntextmenu=stop; </script> <script language=javascript> _error_msg_show('" + strBody + "', 'tmRedir()', '', ''); </script></body></html>");
            HttpContext.Current.Response.End();

        }
10
           /// <param name="strBody">提示信息</param>
        /// <param name="strLocalUrl">转向地址</param>
        /// <param name="blHoldRequest">是否保留当前页面的Request到转向地址页面</param>
        public static void WriteAlert(string strBody, string strLocalUrl, bool blHoldRequest)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> </head> <body> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="../js/validateForm.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ return false;} </script> ");
            HttpContext.Current.Response.Write("</body></html>");
            //HttpContext.Current.Response.End();
            HttpContext.Current.Server.Transfer(strLocalUrl, blHoldRequest);
        }
11.
          /// <param name="strBody">提示信息内容</param>
        /// <returns></returns>
        public static void WriteAlert(string strBody)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="../js/validateForm.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ return false;} </script> ");
            HttpContext.Current.Response.Write("</head> <body> <script language=javascript> _error_msg_show('" + strBody + "', 'redir()', '', ''); </script></body></html>");
            //HttpContext.Current.Response.End();
        }
12.
        public static void WriteDialogAlert(string strBody)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="../js/validateForm2.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ return false;} </script> ");
            HttpContext.Current.Response.Write("</head> <body> <script language=javascript> _error_msg_show('" + strBody + "', 'redir()', '', ''); </script></body></html>");
            //HttpContext.Current.Response.End();
        }
13.
         /// <param name="strBody">提示信息内容</param>
               public static void indexWriteAlert(string strBody)
        {
            HttpContext.Current.Response.Write("<!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> <title>MSG</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <link href="../css/css.css" type="text/css" rel="Stylesheet" /> ");
            HttpContext.Current.Response.Write("<script language="javascript" type="text/javascript" src="js/dialog.js"></script> ");
            HttpContext.Current.Response.Write("<script language=javascript>  function redir(){ return false;} </script> ");
            HttpContext.Current.Response.Write("</head> <body> <script language=javascript> _error_msg_show('" + strBody + "', 'redir()', '', ''); </script></body></html>");
            //HttpContext.Current.Response.End();
        }
  
14.
          /// <param name="URL">新窗口的URL</param>
        /// <param name="WindowName">新窗口显示的名称</param>
        /// <param name="Toolbar">是否显示工具栏,yes为显示</param>
        /// <param name="Menubar">是否显示菜单栏,yes为显示</param>
        /// <param name="Scrollbars">是否显示滚动栏,yes为显示</param>
        /// <param name="Resizable">是否允许改变窗口大小,yes为允许</param>
        /// <param name="Location">是否显示地址栏,yes为允许</param>
        /// <param name="Status">是否显示状态栏内的信息(通常是文件已经打开),yes为允许</param>
        /// <param name="Height">窗口高度</param>
        /// <param name="Width">窗口宽度</param>
        /// <param name="Top">窗口距离屏幕上方的象素值</param>
        /// <param name="Left">窗口距离屏幕左侧的象素值</param>
        public static string Client_Open(string URL, string WindowName, bool Toolbar, bool Menubar, bool Scrollbars, bool Resizable, bool Location, bool Status, int Height, int Width, int Top, int Left)
        {
            return "<script>window.open('" + URL + "','" + WindowName + "','toolbar=" + Toolbar + ",')</script>";
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值