国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#實現的JS操作類實例

2020-01-24 02:06:01
字體:
來源:轉載
供稿:網友

本文實例講述了C#實現的JS操作類。分享給大家供大家參考。具體如下:

這個C#類封裝了常用的JS客戶端代碼操作,包括彈出對話框、返回上一頁,通過JS轉向,彈出警告框并轉向等。

using System.Web;namespace DotNet.Utilities{  /// <summary>  /// 客戶端腳本輸出  /// </summary>  public class JsHelper  {    /// <summary>    /// 彈出信息,并跳轉指定頁面。    /// </summary>    public static void AlertAndRedirect(string message, string toURL)    {      string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";      HttpContext.Current.Response.Write(string.Format(js, message, toURL));      HttpContext.Current.Response.End();    }    /// <summary>    /// 彈出信息,并返回歷史頁面    /// </summary>    public static void AlertAndGoHistory(string message, int value)    {      string js = @"<Script language='JavaScript'>alert('{0}');history.go({1});</Script>";      HttpContext.Current.Response.Write(string.Format(js, message, value));      HttpContext.Current.Response.End();    }    /// <summary>    /// 直接跳轉到指定的頁面    /// </summary>    public static void Redirect(string toUrl)    {      string js = @"<script language=javascript>window.location.replace('{0}')</script>";      HttpContext.Current.Response.Write(string.Format(js, toUrl));    }    /// <summary>    /// 彈出信息 并指定到父窗口    /// </summary>    public static void AlertAndParentUrl(string message, string toURL)    {      string js = "<script language=javascript>alert('{0}');window.top.location.replace('{1}')</script>";      HttpContext.Current.Response.Write(string.Format(js, message, toURL));    }    /// <summary>    /// 返回到父窗口    /// </summary>    public static void ParentRedirect(string ToUrl)    {      string js = "<script language=javascript>window.top.location.replace('{0}')</script>";      HttpContext.Current.Response.Write(string.Format(js, ToUrl));    }    /// <summary>    /// 返回歷史頁面    /// </summary>    public static void BackHistory(int value)    {      string js = @"<Script language='JavaScript'>history.go({0});</Script>";      HttpContext.Current.Response.Write(string.Format(js, value));      HttpContext.Current.Response.End();    }    /// <summary>    /// 彈出信息    /// </summary>    public static void Alert(string message)    {      string js = "<script language=javascript>alert('{0}');</script>";      HttpContext.Current.Response.Write(string.Format(js, message));    }    /// <summary>    /// 注冊腳本塊    /// </summary>    public static void RegisterScriptBlock(System.Web.UI.Page page, string _ScriptString)    {      page.ClientScript.RegisterStartupScript(page.GetType(), "scriptblock", "<script type='text/javascript'>" + _ScriptString + "</script>");    }  }}

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼图壁县| 北川| 玛曲县| 凯里市| 和龙市| 仪陇县| 天门市| 淅川县| 盘锦市| 兴国县| 乐安县| 蚌埠市| 定西市| 闻喜县| 隆尧县| 美姑县| 凉城县| 大竹县| 鹤庆县| 拉孜县| 贵阳市| 密山市| 施甸县| 集贤县| 灵武市| 嘉禾县| 朝阳市| 泽州县| 东宁县| 康乐县| 吉木萨尔县| 苍南县| 玛多县| 潍坊市| 甘德县| 洞口县| 仙游县| 清丰县| 时尚| 大足县| 岚皋县|