zoukankan      html  css  js  c++  java
  • 常用的弹出窗口类

        public class Alert
        {

            #region 警告函数
            ///<summary>
            /// 写警告,仅弹出对话框
            ///</summary>
            public static void MessageBox(string text)//弹出对话框
            {
                HttpContext.Current.Response.Write("<Script language=javascript>alert('" + text + "');</script>");
            }
            ///<summary>
            /// 写警告,仅弹出对话框关闭窗口
            ///</summary>
            public static void MessageBoxClose(string text)//弹出对话框
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.close()");
                HttpContext.Current.Response.Write("</script>");
            }

            ///<summary>
            /// 写警告,返回原来页面
            ///</summary>
            public static void MessageBoxBack(string text)//返回原来页面
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.history.go(-1)");
                HttpContext.Current.Response.Write("</script>");
            }
            ///<summary>
            /// 页面转向
            /// text 警告文本,转向页面,转向目标
            ///</summary>
            public static void MessageBoxRedirect(string text, string gourl, string target)
            {
                if (target == "" || target == null)
                { target = "window"; }
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window." + target + ".location='" + gourl + "';");
                HttpContext.Current.Response.Write("</script>");
            }
            ///<summary>
            /// 页面转向
            /// text 警告文本,转向页面
            ///</summary>
            public static void MessageBoxRedirect(string text, string gourl)
            {
                HttpContext.Current.Response.Write("<Script language=javascript>");
                HttpContext.Current.Response.Write("alert('" + text + "');");
                HttpContext.Current.Response.Write("window.location='" + gourl + "';");
                HttpContext.Current.Response.Write("</script>");
            }
            #endregion


            /// <summary>
            /// 处理用户输入的危险代码
            /// </summary>
            ///定义InputText函数处理用于输入
            public static string InputText(string inputString, int maxLength)
            {
                StringBuilder retVal = new StringBuilder();     ///构造临时字符串数组
                if ((inputString != null) && (inputString != String.Empty))
                {
                    inputString = inputString.Trim();         ///清空字符串两段的空白符号
                    if (inputString.Length > maxLength)
                    {   ///设置字符串的长度
                        inputString = inputString.Substring(0, maxLength);
                    }
                    for (int i = 0; i < inputString.Length; i++)
                    {
                        switch (inputString[i])
                        {
                            ///去除危险字符串(\ ,/,:,*,?,",<,>,| )
                            case '*':
                            case '|':
                            case '<':
                            case '>':
                            case '/':
                            case '\\':
                            case ':':
                            case '?':
                            case '"':
                                retVal.Append(""); break;
                            default: retVal.Append(inputString[i]); break;
                        }
                    }
                    retVal.Replace("'", " ");
                }
                return retVal.ToString();
            }

     /// <summary>
            /// 动态加载下拉菜单
            /// </summary>
            public static void AddListItem(ListControl control, string value, string text)
            {
                ListItem item = new ListItem();
                item.Text = text;
                item.Value = value;
                control.Items.Add(item);
            }

  • 相关阅读:
    HTML中使用Vue+Dhtmlxgantt制作任务进度图
    Vue中使用js-xlsx导出Data数据到Excel
    Vue生命周期
    ajax调用免费的天气API
    maven无法自动下载依赖包settings.xml文件配置
    idea打开项目没有src目录
    java jdk idea maven安装及配置
    CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://conda.anaconda.org/pytorch
    The procedure entry point OPENSSL_sk_new_reserve could not be located in the dynamic link library
    Nuget打包没有注释显示
  • 原文地址:https://www.cnblogs.com/xiaobaigang/p/821172.html
Copyright © 2011-2022 走看看