一些web开发中常用的、做成cs文件的js代码

本文提供了一系列实用的JavaScript操作示例,包括弹出提示框、页面跳转、刷新页面等功能,便于开发者快速实现网页交互需求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ContractedBlock.gifExpandedBlockStart.gif点击前面 + 查看全部代码
None.gifusing System;
None.gif
using System.Web;
None.gif
using System.Web.UI;
None.gif
None.gif
namespace COCOWO.COMP
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 一些常用的Js调用
InBlock.gif    
/// 创建时间:2006-8-3
InBlock.gif    
/// 创建者:马先光
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class Jscript
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{        
InBlock.gif               
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 弹出JavaScript小窗口
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="js">窗口信息</param>

InBlock.gif        public static void Alert(string message)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>
InBlock.gif                    alert('
" + message + "');</Script>";
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 弹出消息框并且转向到新的URL
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="message">消息内容</param>
ExpandedSubBlockEnd.gif        
/// <param name="toURL">连接地址</param>

InBlock.gif        public static void AlertAndRedirect(string message, string toURL)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = "<script language=javascript>alert('{0}');window.location.replace('{1}')</script>";
InBlock.gif            HttpContext.Current.Response.Write(
string.Format(js, message, toURL));
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 回到历史页面
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="value">-1/1</param>

InBlock.gif        public static void GoHistory(int value)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>
InBlock.gif                    history.go({0});  
InBlock.gif                  </Script>
";
InBlock.gif            HttpContext.Current.Response.Write(
string.Format(js, value));
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 关闭当前窗口
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void CloseWindow()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>
InBlock.gif                    parent.opener=null;window.close();  
InBlock.gif                  </Script>
";
InBlock.gif            HttpContext.Current.Response.Write(js);
InBlock.gif            HttpContext.Current.Response.End();
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 刷新父窗口
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void RefreshParent(string url)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<script>try{top.location="""+url+@"""}catch(e){location="""+url+@"""}</script>";
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif       
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 刷新打开窗口
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void RefreshOpener()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>
InBlock.gif                    opener.location.reload();
InBlock.gif                  </Script>
";
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开指定大小的新窗体
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="url">地址</param>
InBlock.gif        
/// <param name="width"></param>
InBlock.gif        
/// <param name="heigth"></param>
InBlock.gif        
/// <param name="top">头位置</param>
ExpandedSubBlockEnd.gif        
/// <param name="left">左位置</param>

InBlock.gif        public static void OpenWebFormSize(string url, int width,int heigth,int top,int left)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>window.open('" + url + @"','','height=" + heigth + ",width=" + width + ",top="+top+",left="+left+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=no,toolbar=no,directories=no');</Script>";
InBlock.gif
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif       
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 转向Url制定的页面
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="url">连接地址</param>

InBlock.gif        public static void JavaScriptLocationHref(string url)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<Script language='JavaScript'>
InBlock.gif                    window.location.replace('{0}');
InBlock.gif                  </Script>
";
InBlock.gif            js 
= string.Format(js, url);
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 打开指定大小位置的模式对话框
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="webFormUrl">连接地址</param>
InBlock.gif        
/// <param name="width"></param>
InBlock.gif        
/// <param name="height"></param>
InBlock.gif        
/// <param name="top">距离上位置</param>
ExpandedSubBlockEnd.gif        
/// <param name="left">距离左位置</param>

InBlock.gif        public static void ShowModalDialogWindow(string webFormUrl, int width, int height, int top, int left)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string features = "dialogWidth:" + width.ToString() + "px"
InBlock.gif                
+ ";dialogHeight:" + height.ToString() + "px"
InBlock.gif                
+ ";dialogLeft:" + left.ToString() + "px"
InBlock.gif                
+ ";dialogTop:" + top.ToString() + "px"
InBlock.gif                
+ ";center:yes;help=no;resizable:no;status:no;scroll=yes";
InBlock.gif            ShowModalDialogWindow(webFormUrl, features);
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static void ShowModalDialogWindow(string webFormUrl, string features)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
string js = ShowModalDialogJavascript(webFormUrl, features);
InBlock.gif            HttpContext.Current.Response.Write(js);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public static string ShowModalDialogJavascript(string webFormUrl, string features)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif            
dot.gif#region
InBlock.gif            
string js = @"<script language=javascript>                            
InBlock.gif                            showModalDialog('
" + webFormUrl + "','','" + features + "');</script>";
InBlock.gif            
return js;
ExpandedSubBlockEnd.gif            
#endregion

ExpandedSubBlockEnd.gif        }
 
InBlock.gif       
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

转载于:https://www.cnblogs.com/hzuIT/articles/758564.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值