易截截图软件、单文件、免安装、纯绿色、仅160KB

javascript在alert之前转义单引号

对于1个单引号,则转义该单引号
对于1个反斜杠跟1个单引号,则不管它。
对于2个及以上的反斜杠加一个单引号,则分别对每个反斜杠和单引号都进行转义,即 使反斜杠数目保持不变, 并转义单引号。
 

/// <summary>
/// 对于单引号而言,若前面有偶数个反斜杠则异常,奇数个反斜杠则正常
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private string ReplaceQuote(string input)
{
string pattern = @"(?:\\)*(?=['])";
return Regex.Replace(input, pattern, new MatchEvaluator(ReplaceText));
}
// 匹配项
public string ReplaceText(Match m)
{
string str = m.Value;
if (str.Length == 0)
{
// 只有单引号,则转义该单引号
return str + @"\";
}
else if(str.Length == 1)
{
// 1个反斜杠加一个单引号,则不替换
return string.Empty;
}
// 对于大于2个长度的反斜杠,则返回原来的2倍
// 即 使把每个反斜杠都转义了。
return new string('\\', 2 * str.Length);
}



protected void Page_Load(object sender, EventArgs e)
{

// 测试代码
string strText = @"'a\'b\\'c\\\'d\\\\'";
System.Diagnostics.Stopwatch swt = new System.Diagnostics.Stopwatch();
swt.Start();
strText = ReplaceQuote(strText);
swt.Stop();
Response.Write("替换使用了毫秒数:" + swt.ElapsedMilliseconds.ToString());
string strAlert = string.Format("alert('{0}')", strText);
ClientScript.RegisterStartupScript(this.GetType(), "alert", strAlert, true);
}


相关文档:

JavaScript 获取对象的高度和宽度详细说明

scrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离
scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
scrollWidth:获取对象的滚动宽度
offsetHeight:获取对象相对于版面或由父坐标 offsetParent 属性指定的父坐标的高度
offsetL ......

C# Active控件,并触发javascript事件

创建一个Winform用户控件 UserControl1
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace MyActiveT ......

javascript 转换为UNIX时间戳,PHP可用

//转换为UNIX时间戳
function strtotimestamp(datestr)
{
    var new_str = datestr.replace(/:/g,"-");
    new_str = new_str.replace(/ /g,"-");
    var arr = new_str.split("-");
    var datum = new Date(Date. ......

javascript简单验证

<html>
  <head>
    <base href="<%=basePath%>">
   
 <script type="text/javascript">
  function check(){
   var name1 = document.form1.name1.value;
   
   var passwor ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号