首页 > 开发 > Javascript > 正文

常用JavaScript代码提示公共类封装

2020-04-24 22:11:15
字体:
来源:转载
供稿:网友
希望对大家有帮助!
代码如下:
using System;
using System.Web;
namespace Jake.PublicJS
{

/// <summary>
/// Summary description for PublicJS
/// </summary>
public class PublicJS
{
public PublicJS()
{
//
// TODO: Add constructor logic here
//
}

/// <summary>
/// 1.静态方法,弹出信息窗体
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void Alert(System.Web.UI.Page page, string description)
{
if (description != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}

/// <summary>
/// 2.静态方法,弹出信息窗体,并刷新页面
/// </summary>
/// <param name="page">页面对象</param>
/// <param name="description">信息内容</param>
/// <example>
/// PublicJS.Alert(this,"NiHao!");
/// </example>
public static void ReLoadMessage(System.Web.UI.Page page, string description, string PageID)
{
if (description != null)
{
string scriptString = "<script language=JavaScript><!--
";
scriptString += "alert('" + description + "');";
scriptString += "parent." + PageID + ".location.reload()";
scriptString += "
// --></script>";
if (!page.IsClientScriptBlockRegistered("clientScript"))
page.RegisterClientScriptBlock("clientScript", scriptString);
}
else
{
Alert(page, "描述信息为空!");
}
}
public static void Redirect(string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
/n");
Response.Write("window.location='" + url + "';/n");
Response.Write("
// --></script>/n");
}

/// <summary>
/// 弹出对话框,转向所指页面
/// </summary>
/// <param name="description">提示信息</param>
/// <param name="url">页面</param>
public static void MsgBoxRedrict(string description, string url)
{
HttpResponse Response;
Response = HttpContext.Current.Response;
Response.Write("<script language=JScript><!--
/n");
Response.Write("alert('" + description + "');/n");
Response.Write("window.location='" + url + "';/n");
Response.Write("
// --></script>/n");
//Response.Redirect(url);
}

/// <summary>
/// 弹出对话框,确实转向所指页面
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表