C#實(shí)現(xiàn)的JS操作類實(shí)例
更新時(shí)間:2015年03月26日 09:31:34 作者:lele
這篇文章主要介紹了C#實(shí)現(xiàn)的JS操作類,封裝了C#關(guān)于javascript的彈出對話框、返回上一頁、跳轉(zhuǎn)等常用操作,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了C#實(shí)現(xiàn)的JS操作類。分享給大家供大家參考。具體如下:
這個(gè)C#類封裝了常用的JS客戶端代碼操作,包括彈出對話框、返回上一頁,通過JS轉(zhuǎn)向,彈出警告框并轉(zhuǎn)向等。
using System.Web;
namespace DotNet.Utilities
{
/// <summary>
/// 客戶端腳本輸出
/// </summary>
public class JsHelper
{
/// <summary>
/// 彈出信息,并跳轉(zhuǎn)指定頁面。
/// </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>
/// 直接跳轉(zhuǎn)到指定的頁面
/// </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#程序設(shè)計(jì)有所幫助。
相關(guān)文章
C#實(shí)現(xiàn)txt定位指定行完整實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)txt定位指定行的方法,涉及C#針對文本文件進(jìn)行光標(biāo)定位的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08
C#運(yùn)算符之與,或,異或及移位運(yùn)算小結(jié)
本文是對C#中的與,或,異或及移位運(yùn)算進(jìn)行了詳細(xì)的介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-10-10
C#中私有構(gòu)造函數(shù)的特點(diǎn)和用途實(shí)例解析
這篇文章主要介紹了C#中私有構(gòu)造函數(shù)的特點(diǎn)和用途,需要的朋友可以參考下2014-08-08
C#時(shí)間格式轉(zhuǎn)換為時(shí)間戳的方法步驟
這篇文章主要介紹了C#時(shí)間格式轉(zhuǎn)換為時(shí)間戳的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
C#實(shí)現(xiàn)支付寶沙箱支付的項(xiàng)目實(shí)踐
本文主要介紹了C#實(shí)現(xiàn)支付寶沙箱支付的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05

