处理HTML代码的若干函数
发布时间:2009-08-21 13:21:00
经过了上个星期的努力学习,对处理html又有了新的发现
感觉真的很不错
可以说js的威力在处理html代码方面我又有所领悟了
1、截取特定长度字符串
Public Shared Function CutString1(ByVal str As String, ByVal length As Integer) As String
Dim i As Integer = 0
Dim j As Integer = 0
For Each chr As Char In str
If Asc(chr) > 127 Then
i = i + 2
Else
i += 1
If (i > length) Then
str = str.Substring(0, j) + ""
Exit For
End If
End If
j += 1
Next
Return str
End Function
2、在在textarea(textbox里面的textmode为dul),对其输入的字符转换成html格式
Public Function HtmlEncode()(ByVal str As String) As String
Dim L As Integer
Dim result As String
If str = "" Then
Return ""
End If
L = Len(str)
Dim i As Integer
For i = 1 To L
Select Case Mid(str, i, 1)
Case Chr(13)
result = result + "<br>"
Case Chr(34)
result = result + """
Case Chr(32)
'result=result+" "
If i + 1 <= L And i - 1 > 0 Then
If Mid(str, i + 1, 1) = Chr(32) Or Mid(str, i + 1, 1) = Chr(9) Or Mid(str, i - 1, 1) = Chr(32) Or Mid(str, i - 1, 1) = Chr(9) Then
result = result + " "
Else
result = result + " "
End If
Else
result = result + " "
End If
Case Chr(9)
result = result + " "
Case Else
result = result + Mid(str, i, 1)
End Select
Next
Return result
End Function
3、在textarea(textbox里面的textmode为dul),对其输入的字符转换成html格式输出
Public Shared Function StripHTML()
Function StripHTML(ByVal strHtml As String) As String
Dim aryReg() As String = New String() {"<script[^>]*?>.*?</script>", "<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]ws[^\7])*?\7ws\w+)ws.{0})ws\s)*?(\/\s*)?>", "([\r\n])[\s]+", "&(quotws#34);", "&(ampws#38);", "&(ltws#60);", "&(gtws#62);", "&(nbspws#160);", "&(iexclws#161);", "&(centws#162);", "&(poundws#163);", "&(copyws#169);", "&#(\d+);", "-->", "<!--.*\n"}
Dim aryRep() As String = {"", "", "", """", "&", "", "", " ", "\xa1", Chr(161), "\xa2", Chr(162), "\xa3", Chr(163), "\xa9", Chr(169), "", "\r\n", ""}
Dim NewReg As String = aryReg(0)
Dim strOutput As String = strHtml
Dim i As Integer
For i = 0 To aryReg.Length - 1 Step i + 1
Dim regex As Regex = New Regex(aryReg(i), RegexOptions.IgnoreCase)
strOutput = regex.Replace(strOutput, aryRep(i))
Next
strOutput.Replace("<", "")
strOutput.Replace(">", "")
strOutput.Replace("\r\n", "")
Return strOutput
End Function
4、一个plus js代码,作用是把所有的tooltip格式化后转变一个层,特定输出
var pltsPop=null;
var pltsoffsetX = 10;
var pltsoffsetY = 15;
var pltsPopbg="#ffff00";
var pltsPopfg="#111111";
var pltsTitle="";
document.write('<div id=pltsTipLayer style="display: none;position: absolute; z-index:10001"></div>');
function pltsinits()
{
document.onmouseover = plts;
document.onmousemove = moveToMouseLoc;
}
function plts()
{ var o=event.srcElement;
if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
pltsPop=o.dypop;
if(pltsPop!=null&&pltsPop!=""&&typeof(pltsPop)!="undefined")
{
pltsTipLayer.style.left=-1000;
pltsTipLayer.style.display='';
var Msg=pltsPop.replace(/\n/g,"<br>");
Msg=Msg.replace(/\0x13/g,"<br>");
var re=/\{(.[^\{]*)\}/ig;
if(!re.test(Msg))pltsTitle="[MyTopWin.Com] 拓文CMS ASP.net系统";
else{
re=/\{(.[^\{]*)\}(.*)/ig;
pltsTitle=Msg.replace(re,"$1")+" ";
re=/\{(.[^\{]*)\}/ig;
Msg=Msg.replace(re,"");
Msg=Msg.replace("<br>","");}
var content =
'<table style="FILTER:alpha(opacity=90) shadow(color=#bbbbbb,direction=150);" id=toolTipTalbe border=0><tr><td width="100%"><table class=selet_bg cellspacing="0" cellpadding="0" style="width:100%" style="font size:11px;">'+
'<tr id=pltsPoptop><th height=12 valign=bottom class=header><p id=topleft align=left>↖'+pltsTitle+'</p><p id=topright align=right style="display:none">'+pltsTitle+'↗</font></th></tr>'+
'<tr><td style="padding-left:10px;padding-right:10px;padding-top: 4px;padding-bottom:4px;line-height:135%">'+Msg+'</td></tr>'+
'<tr id=pltsPopbot style="display:none"><th height=12 valign=bottom class=header><p id=botleft align=left>↙'+pltsTitle+'</p><p id=botright align=right style="display:none">'+pltsTitle+'↘</font></th></tr>'+
'</table></td></tr></table>';
pltsTipLayer.innerHTML=content;
toolTipTalbe.style.width=Math.min(pltsTipLayer.clientWidth,document.body.clientWidth/2.2);
moveToMouseLoc();
return true;
}
else
{
pltsTipLayer.innerHTML='';
pltsTipLayer.style.display='none';
return true;
}
}
function moveToMouseLoc()
{
if(pltsTipLayer.innerHTML=='')return true;
var MouseX=event.x;
var MouseY=event.y;
//window.status=event.y;
var popHeight=pltsTipLayer.clientHeight;
var popWidth=pltsTipLayer.clientWidth;
if(MouseY+pltsoffsetY+popHeight>document.body.clientHeight)
{
popTopAdjust=-popHeight-pltsoffsetY*1.5;
pltsPoptop.style.display="none";
pltsPopbot.style.display="";
}
else
{
popTopAdjust=0;
pltsPoptop.style.display="";
pltsPopbot.style.display="none";
}
if(MouseX+pltsoffsetX+popWidth>document.body.clientWidth)
{
popLeftAdjust=-popWidth-pltsoffsetX*2;
topleft.style.display="none";
botleft.style.display="none";
topright.style.display="";
botright.style.display="";
}
else
{
popLeftAdjust=0;
topleft.style.display="";
botleft.style.display="";
topright.style.display="none";
botright.style.display="none";
}
pltsTipLayer.style.left=MouseX+pltsoffsetX+document.body.scrollLeft+popLeftAdjust;
pltsTipLayer.style.top=MouseY+pltsoffsetY+document.body.scrollTop+popTopAdjust;
return true;
}
pltsinits();


猜你喜欢
- 很多网友在浏览网页时应该会发现很多网页有显示时间和日期的功能,这个不难,使用可视化网页制作软件Drea
- swoole —— 重新定义PHPswoole 的进程之间有两种通信方式,一种是消息队列(queue),另一种是管道(pipe),对swoo
- 下面就来介绍下SQL Server 2008中使用的端口有哪些:首先,最常用最常见的就是1433端口。这个是数据库引擎的端口,如果我们要远程
- 前言gif图就是动态图,它的原理和视频有点类似,也是通过很多静态图片合成的.本篇文章主要介绍,如何利用Python快速合成gif图,主要利用
- 一、去除空格strip()" xyz ".strip() &n
- 前言你是否曾经想将某张照片中的人物抠出来,然后拼接到其他图片上去,从而可以即使你在天涯海角,我也可以到此一游?专业点的人使用 PhotoSh
- 本文实例讲述了python实现矩阵乘法的方法。分享给大家供大家参考。具体实现方法如下:def matrixMul(A, B):
- 介绍图灵完备性(Turing completeness)是通用计算机的一个属性,它表示一个程序可以写另一个程序。比如 go test 命令:
- 1、pd.cut函数有7个参数,主要用于对数据从最大值到最小值进行等距划分 pandas.cut(x, bins,&nb
- 我们现在使用的验证手段都是以验证码为主,让用户根据图片输入验证字符,这种方法的安全度尚可,但会给用户带来一些不便和困扰,比如这个雅虎的验证码
- 之前在训练网络的时候加载数据都是稀里糊涂的放进去的,也没有理清楚里面的流程,今天整理一下,加深理解,也方便以后查阅。pytorch+skle
- 这篇文章主要介绍了基于python实现把图片转换成素描,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋
- 工作需要开始学Perl,下载个Window版(5.16)的: 下载链接 http://www.activestate.com/activep
- pytorch 中的 state_dict 是一个简单的python的字典对象,将每一层与它的对应参数建立映射关系.(如model的每一层的
- 本文实例讲述了Python中的错误和异常处理操作。分享给大家供大家参考,具体如下:#coding=utf8print ''&
- 基础介绍今天我跟大家把我理解的这一块全面的介绍下,配有sql语句送给大家。首先来给大家做个这一块的介绍:1,自连接说到底就是多张表都是同一张
- ndarray的转置(transpose)对于A是由np.ndarray表示的情况:可以直接使用命令A.T。也可以使用命令A.transpo
- 前几日在使用MySQL数据库的时候,出现了一处保存,故作此记录✍问题描述下面是我这样exam表的结构mysql> desc exam;
- 背景每次加载数据都要重新Load,想通过加入的注解方式开发缓存机制,每次缓存不用写代码了缺点:目前仅支持一个返回值,虽然能弄成字典,但是已经
- Splash是一个javascript渲染服务。它是一个带有HTTP API的轻量级Web浏览器,使用Twisted和QT5在Python